function readOnly(count){ }
Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
trigger AccountIndustry on Account (after update) { map<id,Account> mapacc= new Map<Id,Account>(); for(Account acc: Trigger.new){ Account OldAccount = Trigger.oldmap.get(acc.id); if(acc.industry!=oldAccount.Industry){ mapacc.put(acc.id,acc); } } if(mapacc.size()>0){ List<Contact> clist=[select id,Account_Industry__c,Accountid from Contact where accountid in :mapacc.keySet()]; List<Contact> contoupdate= new List<Contact>(); for(Contact con:clist){ if(mapacc.containsKey(con.accountid)){ con.Account_Industry__c=mapacc.get(con.AccountId).industry; contoupdate.add(con); } } if(contoupdate.size()>0) update contoupdate; } }
trigger UpdateIndustryInContacts on Account (after Update) { map<Id,string>AccountIds = new map<Id,string>(); if(trigger.IsAfter && trigger.IsUpdate){ for(Account oAcc : trigger.new){ if(oAcc.Industry != trigger.oldMap.get(oAcc.Id).Industry){ AccountIds.put(oAcc.Id,oAcc.Industry); } } } list<Contact> lstContacts = [Select Id,AccountId from Contact Where AccountId In :AccountIds.keyset() ]; for(Contact oCon : lstContacts){ if(AccountIds.containsKey(oCon.AccountId)){ oCon.Industry__c = AccountIds.get(oCon.AccountId); } } update lstContacts; }
Can you try the below apex trigger on Account Object.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
Try Below Trigger Please Mark It As Best Asnwer If It Helps
Thank You!