You need to sign in to do that
Don't have an account?

Updating contact phone whenever account phone is updated
trigger UpdateAccount2 on Account (before update) { List<Contact> lst=new List<contact>(); List<Account> acc=[select id,phone,(select id,phone from contacts) from account where id in: trigger.newmap.keyset()]; for(Account a:acc) { for(Contact c:a.contacts) { c.phone=a.phone; system.debug(c.phone); lst.add(c); } } update lst; }
This is my Code and Its not working,can anyone what's wrong in my code.
You are not able to update because of the SOQL doing on Account inside the Account trigger only. In that case your code has not yet committed in DB, so that you will get old account values only.
Try this code it will work for you.
Trigger: Handler Class:
And Mark your ans if it works
Thanks
Niraj
Try below code. It's working fine.
Please mark it as best Answer if you find it helpful.
Please let me know if you have any query.
Thank You
Ajay Dubedi