You need to sign in to do that
Don't have an account?
prasanth kumar
mass update contacts otherphone when account phone is updated
Program not shownig error, but when i am editing and saving the phone number in account object, the corresponding contacts otherphone number is not changing. please help.
trigger updatecontacts on Account (before update) { map<id,account> m1=new map<id,account>(); for(integer i=0;i<trigger.new.size();i++) { if(trigger.old[i].phone!=trigger.new[i].phone) { m1.put(trigger.old[i].id,trigger.new[i]); } } list<contact> cons=new list<contact>(); for(contact c:[select id,accountid,otherphone from contact where id in:m1.keyset()]) { account a1=m1.get(c.accountid); c.otherphone=a1.phone; cons.add(c); } update cons; }
As you are performing DML operation on another object, you should write a trigger on "after update"
Please try following code:
If its helps, please mark as best answer so it will help to other who will serve same problem.
Thanks!
All Answers
As you are performing DML operation on another object, you should write a trigger on "after update"
Please try following code:
If its helps, please mark as best answer so it will help to other who will serve same problem.
Thanks!
I will suggest modifying your trigger with the "after" keyword for handling your update
Try modifying your code as follows ;
Regards,
Alexandre
Shrikant Bagal, i changed to after, but not updating. please help. i tried this trigger in another dummy developer account also. but not working.
Shrikant Bagal, i actually saw this code and modified as per my requirememnt. please see this original code.
Note:- if i run this origianl trigger then the values are updating, but this code is not for phone number and it is for address.