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
santhiya duraisanthiya durai 

when update a Parent record, all the related Records needs to be updated with parent record value


Use Case: If I update a Agreement record ,then all the related Agreements to be updated with Termination Date on Parent agreement record.
On Agreement we have Relationship from and Relationship To Related list.  All the Child records will be created in Relationship From Related List. Parent record will appear in Relationship To Related List.This is nothing but Related agreement records and these are Related Agreement object. On Related Agreement we have Relationship from and Relationship To Lookup fields. Relationship from is the parent agreement record and Relationship To is child Agreement Record.
If we Update Parent agreement then agreement(child agreement) should be updated with same Termination date field value on Parent.
I have created this trigger but am getting 0 rows at line # 16 and null value @11
Class:
public class TerminationDate { public static Boolean isFirstTime = true; }
trigger TerminationDateOnParent on Apttus__APTS_Agreement__c (after insert,after update) {

    if(TerminationDate.isFirstTime){
        TerminationDate.isFirstTime = false;

        Map<Id,Date> acc = new Map<Id,Date>();
        for(Apttus__APTS_Agreement__c a:Trigger.New)    {
    if(a.Apttus__Status_Category__c=='Terminated') {
        Apttus__APTS_Related_Agreement__c ar=new Apttus__APTS_Related_Agreement__c();
        acc.put(a.id,ar.Apttus__APTS_Contract_From__r.CLM_Agreement_Termination_Date__c);
        system.debug(acc);
    }
}
   
        
 List<Apttus__APTS_Related_Agreement__c> relagrmt=[select id,Name,Apttus__APTS_Contract_From__r.id,Apttus__APTS_Contract_To__r.id,Apttus__APTS_Contract_From__r.CLM_Agreement_Termination_Date__c,Apttus__APTS_Contract_To__r.CLM_Agreement_Termination_Date__c,Apttus__APTS_Contract_To__r.Name from Apttus__APTS_Related_Agreement__c where id in:acc.keyset()];
       
        for(Apttus__APTS_Related_Agreement__c ag:relagrmt){
            ag.Apttus__APTS_Contract_To__r.CLM_Agreement_Termination_Date__c=acc.get(ag.id);
            system.debug(ag.Apttus__APTS_Contract_To__r.CLM_Agreement_Termination_Date__c);
            
    update ag;
    system.debug(ag);
}
    
    }
}