You need to sign in to do that
Don't have an account?
Mohd Nabeel
t: execution of AfterUpdate caused by: System.FinalException: Record is read-only: What i am doing wrong???
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; } } } } }
List<Account> lstAccountToUpdate = new List<Account>();
for (Account acc: acctList){
Account tempAccount = new Account (Id = acc.Id);
for(Contact con : accsWithContactMap.get(acc.Id).Contacts){
if(acc.BillingPostalCode != con.MailingPostalCode){
tempAccount .OutofZip__c = true;
}
}
lstAccountToUpdate .add(tempAccount);
}
if(!lstAccountToUpdate.isEmpty()){
update lstAccountToUpdate ;
}
Review all error messages below to correct your data.
Apex trigger InsertContact caused an unexpected exception, contact your administrator: InsertContact: execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0 with id 0012v00002cJi2UAAS; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, InsertContact: maximum trigger depth exceeded Account trigger event AfterInsert Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate: []: Class.AccountContact.onBefore: line 18, column 1
Getting this error
Thanks.