From 6fd06751b6abe3e1c8ad842e92558fc849f9406d Mon Sep 17 00:00:00 2001 From: Suyash More Date: Tue, 1 Oct 2024 14:22:11 +0530 Subject: [PATCH] Changes in 'createAddressFromContactAndSetCurrentAddressLookupId' method of ContactAdapter.cls --- .../adapter/in/sobjects/contact/ContactAdapter.cls | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/force-app/main/adapter/in/sobjects/contact/ContactAdapter.cls b/force-app/main/adapter/in/sobjects/contact/ContactAdapter.cls index 67e682b5edc..cff47fe881c 100644 --- a/force-app/main/adapter/in/sobjects/contact/ContactAdapter.cls +++ b/force-app/main/adapter/in/sobjects/contact/ContactAdapter.cls @@ -679,9 +679,7 @@ public inherited sharing class ContactAdapter extends fflib_SObjects2 { // Add the new address to be inserted contactAddressesToInsertByContact.put(contact, newAddress); - - // Link the new address to the contact's Current Address field - contact.Current_Address__c = newAddress.Id; + } else if (contactAddressHasAddressMatch(existingAddressFromContact)) { updateContactAddressFromExistingAddress(contact, existingAddressFromContact); @@ -696,6 +694,16 @@ public inherited sharing class ContactAdapter extends fflib_SObjects2 { } // Insert the new addresses created for contacts with Address Override insertContactAddresses(contactAddressesToInsertByContact); + + for (Contact contact : contactAddressesToInsertByContact.keySet()) { + Address__c insertedAddress = contactAddressesToInsertByContact.get(contact); + if (insertedAddress != null && insertedAddress.Id != null) { + contact.Current_Address__c = insertedAddress.Id; // Now set the address ID + } + else + contact.Current_Address__c = null; + + } } private Set getAddressCreationQueueBeforeUpdate() {