You need to sign in to do that
Don't have an account?
Aman Mishra 01
Write a Trigger :-> {Please help me to solve this Problem}
Whenever I update the Account Phone , Then please, update it's Related Contact Phone Number If related Contact Exist .
Please try the below code - Output: Go to any Account and update the phone number. The phone number in its related contacts automatically gets updated.
I hope you find the above solution helpful. If it does, please mark it as the Best Answer to help others too.
Thanks and Regards,
Suraj Tripathi
All Answers
Please try the below code - Output: Go to any Account and update the phone number. The phone number in its related contacts automatically gets updated.
I hope you find the above solution helpful. If it does, please mark it as the Best Answer to help others too.
Thanks and Regards,
Suraj Tripathi
try below trigger.
don't forget to mark it as best answer.
Thank you
please try below code
trigger updateContact on Account (after update) {
List <contact> contactList = new List <Contact>();
Set <Id> accountIdSet = new Set <Id>();
Map <Id,String> accountMap = new Map <Id,string> ();
for(Account acc:trigger.new) {
if(acc.phone != null && Trigger.oldMap.get(acc.Id).phone != acc.phone) {
accountIdSet.add(acc.id);
}
List<Contact>conList= [select id,accountId,Phone from contact where accountId in:accountIdSet];
for(Contact con:conList) {
if(accountMap != null && accountMap.containsKey(con.accountId)) {
con.phone = accountMap.get(con.accountId);
contactList.add(con);
}
}
if(contactList.size() >0) {
update contactList;
}
}
}