You need to sign in to do that
Don't have an account?
Deepu sfdc
update contact phone field
Hi,
whenever account phone is updated i want to update the contact phone field too.
How can we achieve this with triggers..
can you send me the trigger code
Thanks in Advance
Try this and let us know if it works. Thanks,
Nagendra
Hi nagendra
this trigger is on contact object ... i want to update the contact field when ever we update the account field
BTW im getting this error with this code
Error: Compile Error: Comparison arguments must be compatible types: String, Schema.SObjectField at line 3 column 13
Please try this code if you want to update contact Phone field if account phone field is updated.
trigger AccountFieldUpdateTrigger on Account (After Update) {
//MAP that will hold the contacts related to an account...
Map<Id,List<Contact>> conMap=new Map<Id,List<Contact>>();
List<Contact> conList=[select name,accountId,phone from Contact where accountId in:Trigger.New];
for(Contact c:conList){
if(!conMap.containsKey(c.accountId)){
List<Contact> cList=new List<Contact>();
cList.add(c);
conMap.put(c.accountId,cList);
}
else{
List<Contact> cList= conMap.get(c.AccountId);
CList.add(c);
conMap.put(c.accountId,cList);
}
}
List<Contact> toupdateConList=new List<Contact>();
for( Id accountId : Trigger.newMap.keySet() )
{ //To check whether account phone field is updated...
if( Trigger.oldMap.get( accountId ).Phone != Trigger.newMap.get( accountId ).Phone )
{
for(Contact c: conMap.get(accountId)) {
c.Phone=Trigger.newMap.get( accountId ).Phone;
toupdateConList.add(c);
}
}
}
if(toupdateConList.size()>0){
update toupdateConList;
}
}
Please mark it as best answer if it helps you.
Thanks.
Deepali Kulshrestha
You can do this using process builder.
Thanks