Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. trigger contactAccountTrigger on Account (after update) {
  2. Set<Id> accountIds = new Set<Id>();
  3. List<Contact> contactList1 = new List<Contact>();
  4. //System.debug('1st Loop- Outside');
  5. for(Account acc: Trigger.new){
  6. Account oldAccount = Trigger.oldMap.get(acc.ID);
  7.  
  8. System.debug('1st Loop- inside');
  9. accountIds.add(acc.id);
  10.  
  11.  
  12. }//End of Loop
  13. //System.debug('2nd Loop- Outside');
  14. If(accountIds.size()>0){
  15. Map<Id,Account> mapAccount = new Map<Id,Account> ([select id,Tier__c,Type, (select id,Account_Tier__c,Account_Type__c from contacts ) from account where id in :accountIds ]);
  16. List<Contact> contactList = new List<Contact>();
  17. for(account acc :Trigger.new)
  18. {
  19. //Account oldAccount = Trigger.oldMap.get(acc.ID);
  20.  
  21.  
  22. If(mapAccount.containsKey(acc.id))
  23. {
  24. Account accObj = mapAccount.get(acc.id);
  25. List<Contact> lstCont = accObj.contacts;
  26. for(contact c:lstCont)
  27. {
  28. c.Account_Tier__c=acc.Tier__c;
  29. c.Account_Type__c = acc.Type;
  30. contactList.add(c);
  31. }//end of for loop
  32. System.debug('2nd Loop- Inside');
  33. }
  34.  
  35. } //end of Acc1 for loop
  36.  
  37. if(contactList.size()>0)
  38. {
  39. update contactList1;
  40. }
  41.  
  42. }// End of accountIds.size()
  43.  
  44. }//End of trigger
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement