• Ishwarya
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hello can someone help me on below trigger.
I have a scenario that If account is updating for phone number then all associated contacts phone number should update with same number. 
I wrote the trigger as below.It doesnt throw any errors but the phone number doesnt gets updated.

trigger phupdate on account (after update) 
{
List<contact> ctlist =new list<contact>();
List<Id> ids = new List<Id>();
for(account ac: trigger.new)
{
ids.add(ac.Id);
}
Map<Id, contact> contactMap = new Map<Id, contact>([Select Id, Phone From contact Where Id In :ids]);
for(account ac: trigger.new)
{
contact c = contactMap.get(ac.Id);
if(c != null)
{
ac.Phone= c.Phone;
ctlist.add(c);
}
}
update ctlist;
}
 
  • October 02, 2016
  • Like
  • 0