Please note that i have added the logic in insert and update scenerio as well. And also in case of update if user is updating the mobile field and previously the phone was copied from the mobile field then the mobile field will also update.
Here is trigger code in which we call a apex trigger yaquestion on Contact (after insert,after update) { if(trigger.Isafter && (trigger.Isinsert || trigger.Isupdate)){ // CopyBillingAddress.CopyAddressMailing(trigger.new); yaquest.YaMethod(trigger.new); } }
Below is Apex code
public class yaquest { public static void YaMethod (list<contact> Conlist){ set<Id>Conid=new set<Id>(); for(contact con:Conlist) { Conid.add(con.id); } list<contact> Conobj=new list<contact>(); Conobj=[select phone,MobilePhone from contact where phone=null AND id in :Conid]; for(contact ConLoop:Conobj) { ConLoop.phone=ConLoop.MobilePhone; } update Conobj; } }
Please try the below logic in Trigger.
Please note that i have added the logic in insert and update scenerio as well. And also in case of update if user is updating the mobile field and previously the phone was copied from the mobile field then the mobile field will also update.
Please let me know if you have any issues in the code.
If this solution helps, Please mark it as best answer.
Thanks,
Try Below Trigger Please Mark It As Best Answer If It Helps
Thank You!
you can use the below code
Here is trigger code in which we call a apex
trigger yaquestion on Contact (after insert,after update) {
if(trigger.Isafter && (trigger.Isinsert || trigger.Isupdate)){
// CopyBillingAddress.CopyAddressMailing(trigger.new);
yaquest.YaMethod(trigger.new);
}
}
Below is Apex code
public class yaquest {
public static void YaMethod (list<contact> Conlist){
set<Id>Conid=new set<Id>();
for(contact con:Conlist)
{
Conid.add(con.id);
}
list<contact> Conobj=new list<contact>();
Conobj=[select phone,MobilePhone from contact where phone=null AND id in :Conid];
for(contact ConLoop:Conobj)
{
ConLoop.phone=ConLoop.MobilePhone;
}
update Conobj;
}
}
Thanks