trigger AccountTrigger on Account (before update) {
Map updateAccMap = new Map();
List updatedContacts = new List();
for(Integer i=0; i< trigger.new.size(); i++) {
if(trigger.old[i].ShippingState != trigger.new[i].ShippingState) {
updateAccMap.put(Trigger.old[i].id, Trigger.new[i]);
}
}
//for(Contact c : [Select Id, AccountId, Account_Updated__c From Contact where AccountId IN :updateAccMap.keySet()]) {
for(Contact c : [Select Id, AccountId, Account_Updated__c From Contact where AccountId IN :trigger.old]) {
Account parentAcc = updateAccMap.get(c.AccountId);
c.Account_Updated__c = true;
updatedContacts.add(c);
}
if(!updatedContacts.isEmpty())
update updatedContacts;
}
Like this:
Like Loading...