Data consistency across related records is a foundational requirement for a reliable Salesforce CRM. When contact information changes at the Account level, it’s critical that associated records—like Contacts—reflect those changes automatically to avoid confusion, communication delays, and data mismatches.
In this blog, we explore a powerful Apex trigger that solves exactly that: when an Account’s Phone
field is updated, this trigger propagates the new value to the HomePhone
field of all related Contacts. The trigger is optimized using Map-based logic to ensure bulk safety, efficiency, and scalability across high-volume updates.
This kind of automation is especially helpful in orgs where Account and Contact data are used across departments for sales, service, and support.
🧠 Why This Trigger Is Important
When contact data is siloed or inconsistent, it leads to breakdowns in communication and workflow execution. If an Account’s main phone number is updated but its Contacts still reflect outdated numbers, the result is:
-
Missed calls
-
Ineffective sales or service follow-ups
-
Incorrect reports and dashboards
-
Disrupted customer experience
This trigger ensures that the HomePhone
field of every related Contact stays synchronized with the Account’s updated Phone
value—keeping all teams aligned and up-to-date.
🔍 What This Blog Covers
-
How to use an after update Apex trigger to sync child records
-
How to efficiently detect
Phone
field changes usingTrigger.oldMap
-
How to build a Map-based structure to associate Accounts with Contacts
-
Why this pattern ensures both performance and clarity in large orgs
-
How to structure logic in a handler class for maintainability
-
Real-world use cases where syncing Account and Contact data matters
This solution is not only functional—it’s scalable, production-safe, and built to handle real-life scenarios involving large data volumes and complex CRM processes.
🎯 Real-World Use Cases for This Trigger
-
B2B organizations where the Account phone number acts as the primary number for all related Contacts
-
Customer service teams using Contact records to reach clients quickly
-
Sales teams referencing Contact records in mobile or offline tools synced from Salesforce
-
Data management or cleanup operations requiring field alignment
-
ServiceCloud orgs where accuracy in communication details is essential for SLAs and support
By automating this sync, your CRM becomes a reliable, unified source of contact data that enhances both internal processes and customer engagement.
👨💻 Developer & Admin Tips
The trigger uses Map logic to ensure high efficiency, especially when dealing with bulk updates. Here’s how it works:
-
The trigger compares
Phone
values usingTrigger.oldMap
to detect actual changes -
It builds a
Map<Id, Account>
only for Accounts where thePhone
was changed -
A single SOQL query retrieves all related Contacts for these Accounts
-
Each Contact’s
HomePhone
field is updated with the new Account Phone -
Finally, the updated Contacts are pushed using a single DML statement
This ensures:
-
Minimal SOQL and DML operations
-
Bulk-safe logic that handles multiple Accounts in one go
-
Clean and readable separation of business logic via a handler class
It’s also flexible enough to be extended—if your org uses a custom phone field or needs to sync multiple fields, this same pattern can be reused easily.
🎥 See It In Action – YouTube Playlist Included
If you’re a visual learner or want a live walkthrough, check out the Salesforce Makes Sense YouTube playlist linked in this post. You’ll see:
-
How the trigger works in real-time
-
How Map logic improves performance and scalability
-
Where to place and test the logic inside your dev org
These videos break down technical concepts into real-world scenarios—ideal for admins, developers, and learners looking to deepen their Apex skills.
Solution:
trigger AccountTrigger on Account (after update) {
if(Trigger.isUpdate){ if(Trigger.isAfter){
AccountTriggerHandler.updateRelatedConts(Trigger.New, Trigger.oldMap);
}
}
}
public class AccountTriggerHandler { public static void
updateRelatedConts(List<Account> accList,Map<Id,,Account> oldMap){
List<Contact> conList=new List<Contact>();
Map<id,Account> accToAccountMap= new Map<id,Account>();
for(Account acc:accList){ if((acc.Phone!=null
&& acc.Phone!=(oldMap.get(acc.Id).Phone))
&& oldMap!=null){
accToAccountMap.put(acc.Id,acc);
}
}
for(Contact cont:[SELECT Id, HomePhone, AccountId FROM Contact
WHERE AccountId IN: accTOAccountMap.keySet()]){
if(accToAccountMap.containsKey(cont.AccountId)){
cont.HomePhone=accToAccountMap.get(cont.AccountId).
Phone;
conList.add(cont);
}
} if(!conList.isEmpty()){ update
conList;
}
OR
if(conList.size() > 0){ update conList;
}
}
}