You need to sign in to do that
Don't have an account?
Deepu sfdc
Trigger to update child records
Hi,
I want to update the contact phone field whenever account phone filed is updated .
Please share the code.
Thanks in advance
I want to update the contact phone field whenever account phone filed is updated .
Please share the code.
Thanks in advance
The code is given below:
trigger tri on Account (after update) {
tri_helper.acontPhon(trigger.new);
}
public class tri_helper {
public static void acontPhon(list<Account> acList)
{
List<Contact> cList=new List<Contact>();
for(Contact c:[SELECT Id,phone,account.phone From Contact Where AccountId IN:acList])
{
c.phone=c.Account.phone;
cList.add(c);
}
if(cList.size()>0)
update cList;
}
}
Please mark this as Best Answer if you find this solution helpful.
Thank You
Ajay Dubedi
All Answers
I trust you are doing very well.
Below is the sample code which I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks and Regards,
Khan Anas
The code is given below:
trigger tri on Account (after update) {
tri_helper.acontPhon(trigger.new);
}
public class tri_helper {
public static void acontPhon(list<Account> acList)
{
List<Contact> cList=new List<Contact>();
for(Contact c:[SELECT Id,phone,account.phone From Contact Where AccountId IN:acList])
{
c.phone=c.Account.phone;
cList.add(c);
}
if(cList.size()>0)
update cList;
}
}
Please mark this as Best Answer if you find this solution helpful.
Thank You
Ajay Dubedi