Skip to main content

trigger InsertContact on Account (after insert, after update) {

if( Trigger.isUpdate && Trigger.isAfter){

AccountContact.AccountBillingModify(Trigger.new);

}

}

//Handler class

public class AccountContact{

public static void AccountBillingModify(List<Account> acctList){

Map<Id, Account> accsWithContactMap = new Map<Id, Account>([select id, BillingPostalCode, (select Id, MailingPostalCode from Contacts)

from account

where id in :acctList]);

for (Account acc: acctList){

for(Contact con : accsWithContactMap.get(acc.Id).Contacts){

if(acc.BillingPostalCode != con.MailingPostalCode){

acc.OutofZip__c = true;

}

}

}

}

}

 
3 Antworten
  1. 11. Nov. 2019, 11:04
    Recursion causing this.. please add one static flag as a class member to avoid recursion.

    Thanks.