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 changeAddress on Account ( after update ) { List<contact> listCont=new List<contact>(); Map<string,List<Contact>> cMap = new Map<string,List<Contact>>(); List<Account> lstAcc = new List<Account>(); for(Account A : Trigger.New) { if(A.BillingCity != Trigger.OldMap.get(A.id).BillingCity ) { lstAcc.add(A); } } listCont = [select id,accountid,MailingCity from contact where accountid in :lstAcc]; for(Contact c : listCont) { if(cMap.containsKey(c.Accountid) == false) { List<Contact> lstC = new List<Contact>(); lstC.add(c); cMap.put(c.Accountid, lstC); } else { List<Contact> lstC = cMap.get(c.Accountid); lstC.add(c); } } for(Account A : lstAcc) { if(cMap.containsKey(A.id)) { List<Contact> lstC = cMap.get(A.id); for(Contact C : lstC) { C.MailingCity = A.BillingCity; } } } if(listCont.size() > 0) { update listCont; } }
NOTE :- I have added only BillingCity please add all other field according to your requirement.
Please mark this as solution if this will help you.
Thanks
Amit Chaudhary