Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

W-14578178 Fix Contact Address Override Functionality #7250

Conversation

salesforce-suyash-more
Copy link
Contributor

Critical Changes

GUS W-14578178

To skip the update for contacts with address override, chages made in :

  1. Addresses.cls
  2. ContactAdapter.cls

Changes

Issues Closed

Community Ideas Delivered

Features Intended for Future Release

Features for Elevate Customers

New Metadata

Deleted Metadata

Added changes in Addresses.cls and ContactAdapter.cls to fix Contact Address Override Functionality
Assertions added in 'updatedUndeliverableDefaultAddressDoesNotCauseMultipleOverrideUpdates' method
Copy link
Contributor

@force2b force2b left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of small comments

// if found a match
if (contactAddressHasAddressMatch(existingAddressFromContact)) {
// Check if the contact has Address Override enabled
if (contact.is_Address_Override__c == true) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We typically capitalize the first character of a field name (not counting the namespace of course).

Suggested change
if (contact.is_Address_Override__c == true) {
if (contact.Is_Address_Override__c == true) {

@@ -911,14 +911,16 @@ public with sharing class ADDR_Addresses_TEST {
Test.stopTest();

Address__c updatedAddress = [SELECT Default_Address__c, Undeliverable__c FROM Address__c WHERE Id = :overrideAddressToCreate.Id];
Contact updatedContact = [SELECT Undeliverable_Address__c FROM Contact WHERE Id = :contact.Id];
Contact updatedContact = [SELECT Undeliverable_Address__c,is_Address_Override__c FROM Contact WHERE Id = :contact.Id];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Suggested change
Contact updatedContact = [SELECT Undeliverable_Address__c,is_Address_Override__c FROM Contact WHERE Id = :contact.Id];
Contact updatedContact = [SELECT Undeliverable_Address__c, Is_Address_Override__c FROM Contact WHERE Id = :contact.Id];

force-app/main/domain/Addresses.cls Show resolved Hide resolved
**/__mocks__/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to check in this file?

}

// Check if the contact has Address Override enabled
if (contact.Is_Address_Override__c == true) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a possibility that this logic will create multiple Address records for the same address over time, basically each time the Contact record is edited to change any field value? The original logic appears to have first looked for a matching address before it inserted a new address. The new changes move that check to after the logic to insert a new address.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for bringing this up. The reason we're proceeding to create a new address when Address Override is enabled, without checking for an existing address, is to ensure that the contact’s address remains completely independent of any household address updates.
By generating a new address for each contact with Address Override enabled, we maintain distinct address records for the contact, which aligns with the intended behavior of keeping contact addresses separate from household changes. This prevents any potential conflicts between the contact’s address and the household’s address. For contacts without Address Override, we continue to match existing addresses before inserting new ones to ensure consistency.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. My question though is whether every tiny change to the Contact will create a new Address record. To test:

  • Create a Contact with an Address and the Override set
  • Confirm that there is one Address record linked to that Contact
  • Edit the Contact again to add or change the value in Title
  • Is another Address record created for the same exact address?

If the answer to that last bullet is yes, we'll need to fix that. Let me know what you find.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@force2b, I have tested the scenario where non-address fields like Title are updated, and I confirmed that no new address records are created in such cases. The new address creation is only triggered by changes in address-related fields, as intended.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for testing and confirming.

@@ -197,7 +197,7 @@ private with sharing class ACCT_AccountMerge_TEST {
System.assertEquals(cHH * cCon, listCon.size());

// verify Addresses are merged
System.assertEquals(cHH + 1, [SELECT count() FROM Address__c]);
System.assertEquals(cHH * 2, [SELECT count() FROM Address__c]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why check for double (2x) the number of records here; which I think would be 6 address records? The previous assert was checking for only 4 records. Does the new override cause more address records to be created?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@force2b thank you for your feedback. The assert now checks for double the number of address records because the new Address Override functionality creates a separate address for each contact with the override enabled. Previously, the contacts shared the household address, resulting in fewer records. With the override, each contact now gets its own distinct address, which correctly leads to a higher count. This behavior aligns with the goal of maintaining independent addresses for contacts with Address Override enabled.

@salesforce-suyash-more
Copy link
Contributor Author

@force2b thank you for approving the changes, could you please merge this PR.

@force2b force2b merged commit 74bf617 into feature/254 Oct 11, 2024
9 of 15 checks passed
@force2b force2b deleted the feature/254__W-14578178-fix-contact-address-override-functionality branch October 11, 2024 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants