function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Trigger to update child record of all account contacts


Is it possible to update a child record of all contacts when one of the contact child record is updated? We have a custom object associated to contacts and would like the same record to reflect on all contacts within the same account. For example, Account A has 2 contacts, Contact 1 and Contact 2. Each contact has a child record, namely Child Record 1.a and Child Record 2.a. When Child Record 1.a is updated, Child Record 2.a should also update. Both child records should have the same info.

Is this possible? How do I do this?


You can do this by write a trigger on  Child Record object.
Arpit Patel 8Arpit Patel 8
Yes. It is doable.

When the Child Record is updated, you can get the related Parent Contact record from the Child Record 1.a (via relationship).

Once you get the Parent Contact, then you can all other Child record for the given parent, and update them.

Just some processing in the loop using list and maps. It should be very simple.

You can try to write the code for this so that I can further review. 

Hope this helps.
Reinke, ChrisReinke, Chris
Could you create a field on the Account record and then use a formula field to pull the data from that field to the sub-child records? You would update the field on Account and then all of the sub-children would be updated without using any code.

Thanks guys. I tried writing the trigger but get the following error:

Invalid field Account for SObject PFC_Dependent__c at line 23 column 46

Here's my code:

trigger updatePFCobjects on PFC_Dependent__c (before update) {
    Map<Id, PFC_Dependent__c> updateddependent = new Map<Id,PFC_Dependent__c>();
    for (integer i = 0; i<;i++){
        if((Trigger.old[i].Age__c !=[i].Age__c)
        ||(Trigger.old[i].Contact__c !=[i].Contact__c)
        ||(Trigger.old[i].First_Name__c !=[i].First_Name__c)
        ||(Trigger.old[i].Has_Special_Needs__c !=[i].Has_Special_Needs__c)
        ||(Trigger.old[i].Highest_Level_of_Education__c !=[i].Highest_Level_of_Education__c)
        ||(Trigger.old[i].Last_Name__c !=[i].Last_Name__c)) {
   List<Id> ContactIds = new List <Id>();
       for (integer i=0; i <; i++) {
   List<Id> AccountIds = new List <Id>();
       for (integer i=0; i <; i++) {
   List<Contact> parentObjList = new List<Contact>();  
       for (Contact c : [SELECT id, accountId  
                     FROM contact 
                     WHERE Id  
                     in :updateddependent.keySet()]) { 
       PFC_Dependent__c pfcd =[0];  
           pfcd.Age__c = pfcd.Age__c;
           pfcd.Contact__c = pfcd.Contact__c;
           pfcd.First_Name__c = pfcd.First_Name__c;
           pfcd.Has_Special_Needs__c = pfcd.Has_Special_Needs__c;
           pfcd.Highest_Level_of_Education__c = pfcd.Highest_Level_of_Education__c;
           pfcd.Last_Name__c = pfcd.Last_Name__c;
   update updateddependent;