You need to sign in to do that
Don't have an account?
Priyanka Dumka
trigger that will update all related contacts mailling addresses when account shipping address changes.
Trigger that will update all related contacts mailling addresses when account shipping address changes?
You can take reference of the code snippet from https://salesforce.stackexchange.com/questions/369787/write-a-trigger-on-contact-and-fill-its-mailing-address-with-its-accounts-shipp to get started
https://developer.salesforce.com/forums/?id=9060G000000IBeVQAW
If this information helps, please mark the answer as best. Thank you
// Create a set to store the ids of the contacts that need to be updated
Set<Id> contactIds = new Set<Id>();
// Loop through the accounts that have been updated
for (Account account : Trigger.new) {
// Check if the shipping address has changed
if (account.ShippingStreet != Trigger.oldMap.get(account.Id).ShippingStreet ||
account.ShippingCity != Trigger.oldMap.get(account.Id).ShippingCity ||
account.ShippingState != Trigger.oldMap.get(account.Id).ShippingState ||
account.ShippingPostalCode != Trigger.oldMap.get(account.Id).ShippingPostalCode ||
account.ShippingCountry != Trigger.oldMap.get(account.Id).ShippingCountry) {
// Query for the related contacts
for (Contact contact : [SELECT Id FROM Contact WHERE AccountId = :account.Id]) {
contactIds.add(contact.Id);
}
}
}