Write a trigger after update on account object

Bynayakdillip

Write a trigger after update on account object

trigger AccountTrigger on Account (after insert,before insert,after update) {
if(Trigger.IsAfter && Trigger.IsUpdate){
set accountSetID=new set();
for(Account AccountDetail:Trigger.new){
system.debug('Account Name'+AccountDetail.Name);
system.debug('AccountDetail.id'+AccountDetail.id);
accountSetID.add(AccountDetail.id);//Store ALl Account ID in Set
}
system.debug('accountSetID'+accountSetID.size());
List contactList=[SELECT LastName,FirstName FROM Contact WHERE ACCOUNTID=:accountSetID];//All Contacts
for(Contact ContactDetail:contactList){
ContactDetail.FirstName='IBM'+ ContactDetail.FirstName;
}
system.debug('contactList'+contactList.size());
system.debug('Contact Name'+contactList[0].FirstName);
update contactList;
}

}

About the author

nayakdillip administrator

Leave a Reply