Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trigger contactAccountTrigger on Account (after update) {
- Set<Id> accountIds = new Set<Id>();
- List<Contact> contactList1 = new List<Contact>();
- //System.debug('1st Loop- Outside');
- for(Account acc: Trigger.new){
- Account oldAccount = Trigger.oldMap.get(acc.ID);
- System.debug('1st Loop- inside');
- accountIds.add(acc.id);
- }//End of Loop
- //System.debug('2nd Loop- Outside');
- If(accountIds.size()>0){
- 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 ]);
- List<Contact> contactList = new List<Contact>();
- for(account acc :Trigger.new)
- {
- //Account oldAccount = Trigger.oldMap.get(acc.ID);
- If(mapAccount.containsKey(acc.id))
- {
- Account accObj = mapAccount.get(acc.id);
- List<Contact> lstCont = accObj.contacts;
- for(contact c:lstCont)
- {
- c.Account_Tier__c=acc.Tier__c;
- c.Account_Type__c = acc.Type;
- contactList.add(c);
- }//end of for loop
- System.debug('2nd Loop- Inside');
- }
- } //end of Acc1 for loop
- if(contactList.size()>0)
- {
- update contactList1;
- }
- }// End of accountIds.size()
- }//End of trigger
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement