Trigger for Update Related Contacts Picklist based on Account Picklist in Salesforce
Apex Trigger
trigger UpdateRelatedContactsBasedOnAccount on Account(before update, after update){Set<id> accid =newSet<id>();for(Account a :Trigger.new){if(a.Rating!=null){
accid.add(a.id);}if(!accid.isEmpty()){List<Contact> conList =[select Id,Name,AccountId,
Level__c from Contact where AccountId=: accid];if(!conList.isEmpty()){for(Contact c : conList){if(a.Rating=='Hot'){
c.Level__c='Primary';}elseif(a.Rating=='Warm'){
c.Level__c='Secondary';}elseif(a.Rating=='Cold'){
c.Level__c='Tertiary';}}
update conList;}}}}
No comments:
Post a Comment