• Mohd Ashraf
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
public class Task14 {
 
    public static void beforeupdate(Map<id,Account> oldmap,Map<id,Account> newmap){
        list<id> accid=new list<id>();
        for(id key:oldmap.keySet()){
            Account old=oldmap.get(key);
            Account newmp=newmap.get(key);
            if(old.Phone!=newmp.Phone){
              accid.add(key);
            }
        }
        list<Contact> con=[select lastname,firstname,phone,accountid from Contact where accountid in:accid];
        for(Contact c:con){
            Account a=newmap.get(c.accountid);
            Account b=oldmap.get(c.accountid);
            c.Phone=a.Phone;
            c.OtherPhone=b.phone;
            
        }
        update con;
    }
}
==========================================================

trigger Task14Trigger on Account (before update) {
    if(trigger.isbefore && trigger.isupdate){
        Task14.beforeupdate(Trigger.oldmap, Trigger.newmap);
    }
}
====================================================================