Skip to content
  • Surfmyindia |
  • Lifedreamguide |
  • w3webmart |
  • Overstockphoto |
  • News24globalworld |
  • News24classictimes |
  • Incriediableindia |
  • TechW3web |
  • W3Force ..
w3web.net
Sign Up to Get Free Code Access β†’ |
  • Home
  • Tutorial
    • Lightning Component
    • Salesforce LWC
    • Salesforce Integration
    • Visualforce
    • Trigger
    • JQuery
  • Get Free Courses
  • Integration
  • Aura Comp
  • Salesforce LWC
  • Visualforce
  • Trigger
  • JQuery
  • React Js
  • More
    • About Us
    • Contact Us
    • Sitemap
    • Course Pricing
    • Blog
    • Gallery
    • Most Popular Articles
    • Download E-Book
    • YouTube Channel


Write apex trigger on custom Parent Object (Parent__c) to update the related Child Object (Child__c) Phone whenever Parent__c Phone is Updated | Apex Trigger to update the related Object Phone whenever Parent Phone is updated

November 2, 2025 by Vijay Kumar
151 views

Hey guys, today in this post we are going to learn about how to Write apex trigger on custom Parent Object (Parent__c) to update the related Child Object (Child__c) Phone whenever account Phone is Updated in Salesforce.

You can create an Apex trigger on the Parent__c object that runs after update. The trigger should check if the Phone field has changed, query for the related Child__c records, and then update their Phone field with the new account phone number.

  • Apex trigger to create and count the number of child records associated with parent object based on custom field when parent record is created/updated in Salesforce
  • Apex Trigger to Send a Custom Visualforce Component Email Template when Record is Created on Custom Object in Salesforce
  • Trigger to Update the Custom Last Modified Date Field in the Parent Object When the Records in the Child Object is Updated Using Apex Trigger in Salesforce
  • Trigger to update count of child records with custom field of parent object | count of child records on parent for lookup relationship uses of apex trigger in Salesforce
  • Create rollup summary using Apex trigger on custom object | rollup summary trigger for count of child records on custom object in Salesforce example
  • Create Duplicate Rule & Matching Rule to Prevent Insert/Update Duplicate Records on Contact sObject based on Contact Email and Contact Phone in Salesforce
  • Apex trigger on Account to avoid creation of duplicate record if the account with same phone exists in the system in Salesforce
  • Write a trigger on contact to update parent record when child is updated using apex trigger in Salesforce
  • Write a trigger whenever Opportunity is deleted the corresponding Account and Contact should be deleted uses of Apex trigger in Salesforce
  • Write a trigger on Contact to Prevent the user to create duplicate Contact based on Phone if Phone number is already exist on related account in Salesforce
  • Write Validation rule for StageName of opportunity sObject that don’t allow the user to move Previous/Next Stage based on User/Profile (Except specific profile of user) in Salesforce

 

Create Apex Trigger β†’

Step 1:- Create Apex Controller : parentTrigger.apxt

πŸ‘‰ Download Free Ebook β†’

πŸ‘‰ Get Complementary β†’

right side banner -- www.w3webmart.com

SFDX:Create Apex Trigger>> New >> parentTrigger.apxt

parentTrigger.apxt [Apex Trigger]


  1.  
  2.  
  3.   TRIGGER parentTrigger ON Parent__c (BEFORE INSERT, after INSERT, BEFORE UPDATE, after UPDATE, BEFORE DELETE, after DELETE) {
  4.  
  5.  
  6.    //WRITE apex TRIGGER TO UPDATE the related Contacts Phone whenever account Phone IS updated
  7.  
  8.     IF(TRIGGER.isBefore){
  9.  
  10.     }
  11.     ELSE IF(TRIGGER.isAfter){
  12.  
  13.         IF(TRIGGER.isUpdate){
  14.  
  15.             Set<Id> setId = NEW Set<Id>();            
  16.  
  17.             Map<Id, String> parentPhoneMap = NEW Map<Id, String>();
  18.  
  19.             FOR(Parent__c p1:TRIGGER.new){           
  20.  
  21.                 Parent__c oldParent = TRIGGER.oldMap.get(p1.Id);
  22.                 IF(p1.Phone__c != oldParent.Phone__c){
  23.                     setId.add(p1.Id);
  24.                     parentPhoneMap.put(p1.Id, p1.Phone__c);
  25.                 } 
  26.  
  27.             }
  28.  
  29.  
  30.             List<Child__c> conObjList = [SELECT Id, Phone__c, Parent__c FROM Child__c WHERE Parent__c IN:setId];
  31.  
  32.             List<Child__c> childItem = NEW List<Child__c>();
  33.  
  34.             FOR(Child__c c1:conObjList){             
  35.  
  36.                 String newPhone = parentPhoneMap.get(c1.Parent__c);
  37.                 IF(c1.Phone__c != newPhone){
  38.                     c1.Phone__c = newPhone;
  39.                     childItem.add(c1);
  40.                 }                
  41.             }
  42.  
  43.             IF(!childItem.isEmpty()){
  44.                 UPDATE childItem;
  45.             }
  46.  
  47.  
  48.  
  49.         }
  50.  
  51.     }
  52.  
  53.  
  54. }

 

 

Further post that would you like to learn in Salesforce

  • Trigger on contact to update a account custom field | Write a trigger on contact and update the account custom field uses of apex trigger in Salesforce
  • Create a Apex Trigger on Account to Update the Associated Contact Account Name Null Whenever Account Record is Updated in Salesforce
  • Trigger to check duplicate name to custom object in Salesforce | how to prevent duplicate records based on multiple fields through apex trigger in Salesforce
  • Write a Apex trigger to Add the Contact First Name and Last Name to Associated Account Custom Field Whenever the Contact inserted or Updated in Salesforce
  • Trigger to update parent records field when child record is updated | update parent field from child using apex trigger
  • How to call invocable method (@InvocableMethod) from APEX Controller to convert automatic lead to Account, Contact and Opportunity Uses of Flow Builder/Flow Action in Salesforce
  • Write a trigger to update parent account phone number whenever the contact phone number is updated using trigger handler and helper class in Salesforce
  • Trigger on custom object to prevent delete the related list record based on lookup relation whenever trying to delete parent record, throw an error message using apex class handler trigger in Salesforce
  • Write a trigger on lead to prevent duplicate records based on lead email Whenever the records is inserted Or updated using apex class handler trigger in Salesforce
  • Apex Trigger on Contact to Create Account Automatically and map to related account Id to Contact Whenever New Contact is Created in Salesforce

 

FAQ (Frequently Asked Questions)

What is the after update trigger?

An AFTER UPDATE trigger is a type of trigger that executes after an UPDATE statement is performed on the table. This article provides a complete guide on how to create and use AFTER UPDATE triggers in MySQL including detailed examples and best practices.

How are contacts and accounts related in Salesforce?

The relationship rules are still simple. Every contact needs to be directly associated with an account. This is the account that appears in Account Name and is usually the company the contact is most closely associated with. Any other accounts associated with the contact represent indirect relationships.

What is the difference between trigger before update and after update?

A BEFORE triggered action executes before the triggering statement , that is, before the occurrence of the trigger event. An AFTER triggered action executes after the action of the triggering statement is complete.

Related Topics | You May Also Like

  • If Account Active fields selected β€œYes” and Related Opportunities Stage has β€œClosed Lost” then display error message in Salesforce || If Account Active fields selected β€œYes” and Related Opportunity Stage has β€œClose Lost” then don’t allow to updated record, here we will display error message in SalesforceIf Account Active fields selected β€œYes” and Related Opportunities Stage has β€œClosed Lost” then display error message in Salesforce || If Account Active fields selected β€œYes” and Related Opportunity Stage has β€œClose Lost” then don’t allow to updated record, here we will display error message in Salesforce
  • Apex Trigger to update Account phone from Contact Phone based on lookup relationship in Salesforce | Update the related Account Phone if Contact Record is Created in SalesforceApex Trigger to update Account phone from Contact Phone based on lookup relationship in Salesforce | Update the related Account Phone if Contact Record is Created in Salesforce
  • Trigger on contact to update a account custom field | Write a trigger on contact and update the account custom field uses of apex trigger in SalesforceTrigger on contact to update a account custom field | Write a trigger on contact and update the account custom field uses of apex trigger in Salesforce
  • Write apex trigger to update the related Child__c Phone whenever Parent__c Phone is updated in SalesforceWrite apex trigger to update the related Child__c Phone whenever Parent__c Phone is updated in Salesforce
  • When an Account record is created then Create a related Contact automatically through Apex Trigger in SalesforceWhen an Account record is created then Create a related Contact automatically through Apex Trigger in Salesforce
  • Update all Email of Contact related list to the associated Account if Account is updated in Salesforce |  How to update all Contact record related to Account in SalesforceUpdate all Email of Contact related list to the associated Account if Account is updated in Salesforce | How to update all Contact record related to Account in Salesforce
  • Write a apex trigger on Account, whenever Active is “Yes”, before save the record we will be check the child object (Opportunity) StageName should not be “Closed Lost”, if any of record of child record get “Closed Lost”, it will be through an error.Write a apex trigger on Account, whenever Active is “Yes”, before save the record we will be check the child object (Opportunity) StageName should not be “Closed Lost”, if any of record of child record get “Closed Lost”, it will be through an error.
  • Write a trigger on contact to update parent record when child is updated using apex trigger in Salesforce | How to write trigger to update account Phone when contact Phone is updated in SalesforceWrite a trigger on contact to update parent record when child is updated using apex trigger in Salesforce | How to write trigger to update account Phone when contact Phone is updated in Salesforce

πŸ‘‰ Get Complementary β†’

right side banner -- www.w3webmart.com
 
  
πŸ‘‰ Get Free Course β†’

πŸ“Œ Salesforce Administrators

πŸ“Œ Salesforce Lightning Flow Builder

πŸ“Œ Salesforce Record Trigger Flow Builder

πŸ‘‰ Get Free Course β†’

πŸ“Œ Aura Lightning Framework

πŸ“Œ Lightning Web Component (LWC)

πŸ“Œ Rest APIs Integration



Vijay Kumar

Hi, This is Vijay Kumar behind the admin and founder of w3web.net. I am a senior software developer and working in MNC company from more than 8 years. I am great fan of technology, configuration, customization & development. Apart of this, I love to write about Blogging in spare time, Working on Mobile & Web application development, Salesforce lightning, Salesforce LWC and Salesforce Integration development in full time. [Read full bio] | | The Sitemap where you can find all published post on w3web.net

Categories Trigger, Tutorial Tags Apex trigger to update the related contacts phone whenever account phone is updated, trigger to create account when contact is created, Trigger to update account when contact is inserted, trigger to update account when contact is updated, trigger to update contact email when account email is updated, update contact phone with account phone in salesforce, Write a trigger on contact to sum amount on contact, Write a trigger to find the max amount of Opportunity and update it in Account
Step-by-Step Guide to Getting Started with Salesforce Agentforce | Getting Started With Salesforce Agentforce | Ultimate Salesforce Agentforce Guide
Send Contact Info to External System and Insert Response Record | Create Apex Class for REST API Callout | Hands-on real-world Salesforce example of making a REST API POST callout

Archives β†’

Categories β†’

  • Agentforce (4)
  • Blog (4)
  • More (7)
  • Tutorial (320)
    • Formula Field (1)
    • JQuery (13)
    • Lightning Component (60)
    • React Js (15)
    • Salesforce Integration (41)
    • Salesforce LWC (113)
    • Trigger (53)
    • Validation Rule (9)
    • Visualforce (16)
  • Uncategorized (4)

Global Visitors β†’

Popular Posts β†’

  • Create multiple Contacts in Salesforce Using a Lightning Web Component (LWC) Calling an Apex method Using Database.insert for bulk record insert and Displaying success & error messages 5.50 views per day
  • Create custom path dynamically for a picklist field of Stage in Opportunity Object using lightning:picklistPath in Lightning Component Salesforce | how to create custom lightning path for a picklist field of Stage in Opportunity 3.67 views per day
  • call apex rest service from workbench rest explorer -- w3web.net How to run Apex REST API Post/Put/Patch/Get/Delete through Workbench into Opportunity object in Salesforce | Steps to call apex rest service Post/Put/Patch/Get/Delete from workbench rest explorer in Salesforce | How to make call to apex rest api in... 3.17 views per day
  • convert datetime to date in lwc -- w3web.net How to convert date format Using @track with html tag in lwc | How to format today Date in DD/MM/YYYY in lightning web components | Convert String To Current Date In Salesforce LWC 3 views per day
  • create lightning datatable row actions in lwc -- w3web.net Creating a Lightning Datatable with Row Actions and Display a Modal Popup on Click View Icon Button in Salesforce Lightning Web Component – LWC | how to create lightning datatable row actions in lwc 2.83 views per day
  • Salesforce sends Contact data to an External CRM System using POST REST API, External system returns a Customer Reference ID, salesforce stores that ID in a custom field, Whenever Contact Phone or Email is updated, Salesforce notifies the external sy... 2.83 views per day
  • if and else condition in lwc -- w3web.net How do you use template if:true and template if:false condition to display content in lightning web component – LWC | how to use if and else condition in lwc 2.83 views per day
  • get selected checkbox value in lwc -- w3web.net How to get/set checkbox value in lwc component and display the selected value using of “lightning-checkbox-group” property in Lightning Web Component (LWC) Salesforce | how to get selected checkbox value in lwc 2.67 views per day

Get Free Courses β†’

right side banner -- www.surfmyindia.com
right side banner -- overstockphoto.blogspot.com

Join Our Newsletter β†’

Loading
right side banner -- www.lifedreamguide.com

Recent Posts β†’

  • Write Apex Trigger Whenever a Contact is Inserted / Updated / Deleted, We need to Count child Contacts related to each Account Based on MailingCountry Only for these 4 countries (India, USA, England, Japan) Then store the count on Account object.
  • When an Account’s field Share_With_User__c (a lookup to User) is filled, automatically share that Account with that user via Apex sharing.
  • Add Multiple Rows button (Dynamic Contact Rows) Bulk Insert Contacts Related to Account using Database.insert() in LWC Salesforce
right side banner -- www.w3webmart.com


header banner -- www.overstockphoto.blogspot.com
  • Follow Me β†’
➑ : Facebook
➑ : Twitter
➑ : Linkedin
➑ : Instagram
➑ : Reddit
➑ : Forcetalks
➑ : Pinterest
➑ : Github
➑ : Medium
➑ : Tumblr
➑ : Telegram
 

🧩 Get Free Courses

πŸ‘‰ Get Complementary β†’

right side banner -- www.w3webmart.com
header banner -- www.overstockphoto.blogspot.com

Recent Posts β†’

  • Write Apex Trigger Whenever a Contact is Inserted / Updated / Deleted, We need to Count child Contacts related to each Account Based on MailingCountry Only for these 4 countries (India, USA, England, Japan) Then store the count on Account object.
  • When an Account’s field Share_With_User__c (a lookup to User) is filled, automatically share that Account with that user via Apex sharing.
  • Add Multiple Rows button (Dynamic Contact Rows) Bulk Insert Contacts Related to Account using Database.insert() in LWC Salesforce
  • Create multiple Contacts in Salesforce Using a LWC Using Database.insert for bulk record insert, Single LWC NO template loop NO dynamic rows Insert multiple Contacts related to that Account
  • Create multiple Contacts in Salesforce Using a Lightning Web Component (LWC) Calling an Apex method Using Database.insert for bulk record insert and Displaying success & error messages
  • Apex Trigger Whenever a Contact is updated (Email / Phone), Salesforce calls external REST API again using Queueable Apex | Salesforce sends Contact data using POST REST API using Queueable Apex
header banner -- www.lifedreamguide.com

Popular Posts β†’

  • When an Account’s field Share_With_User__c (a lookup to User) is filled, automatically share that Account with that user via Apex sharing. 7 views
  • get selected checkbox value in lwc -- w3web.net How to get/set checkbox value in lwc component and display the selected value using of “lightning-checkbox-group” property in Lightning Web Component (LWC) Salesforce | how to get selected checkbox value in lwc 5 views
  • convert datetime to date in lwc -- w3web.net How to convert date format Using @track with html tag in lwc | How to format today Date in DD/MM/YYYY in lightning web components | Convert String To Current Date In Salesforce LWC 5 views
  • Write Apex Trigger Whenever a Contact is Inserted / Updated / Deleted, We need to Count child Contacts related to each Account Based on MailingCountry Only for these 4 countries (India, USA, England, Japan) Then store the count on Account object. 5 views
  • Surfmyindia |
  • Lifedreamguide |
  • w3webmart |
  • Overstockphoto |
  • News24classictimes |
  • TechW3web |
  • Refund Policy |
  • Delivery Policy |
  • Privacy Policy |
  • Term & Conditions
© 2026 w3web.net • Built with GeneratePress

Chat Now