Write a trigger to update contact when accounts phone changed.
Trigger to update contact when accounts phone changed
Create a trigger on Account object
Query for related Contacts
Update Contact phone field with Account phone field value
trigger UpdatePhone on Account (after update) {
Map<Id,Account> accToPhoneMap = new Map<Id,Account>();
for(Account acc : Trigger.new){
if(acc.Phone != trigger.oldMap.get(acc.Id).Phone){
accToPhoneMap.put(acc.Id,acc);
}
List<Contact> relatedContact = [Select Id,Name,AccountId, Phone from Contact WHERE AccountId IN :accToPhoneMap.keySet()];
for(Contact con : relatedContact){
con.Phone = accToPhoneMap.get(con.AccountId).Phone;
}
}
}
trigger createContact on Account (before update) {
MAP
List
For(Account acc:trigger.old){
oldMap.put(acc.Id, ...read more
trigger updatedcontact on Account (After Insert){
List
List
for(Account acc : trigger.new)
{
if(acc.Phone != trigger.old...read more
trigger updatedcontact on Account (After Insert){
List
List
for(Account acc : trigger.new)
{
if(acc.Phone != trigger.old...read more
Top Deloitte Salesforce Developer interview questions & answers
Popular interview questions of Salesforce Developer
Top HR questions asked in Deloitte Salesforce Developer
Reviews
Interviews
Salaries
Users/Month