0

We have Agreement object. On Parent agreement we create multiple child agreements, which Child Agreement records will appear in Relationship From Related List. This Related list is a Related Agreement Object. On Related Agreement Object we have two fields.1) Apttus__APTS_Contract_From__c(which refers Parent Record) 2) Apttus__APTS_Contract_To__r(which refers child Record).

On Parent Agreement, if we updated a Termination Date field , On child Agreement Termination Date field should be updated with which we enters on Parent Agreement.

Trigger:

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(ar.Apttus__APTS_Contract_From__r.id,a.CLM_Agreement_Termination_Date__c); system.debug(acc); } }

List agreement = [select id,Name,Apttus__Parent_Agreement__r.Apttus__Status_Category__c,CLM_Agreement_Termination_Date__c,Apttus__Parent_Agreement__r.CLM_Agreement_Termination_Date__c,Apttus__Parent_Agreement__c,Apttus__Status_Category__c,Apttus__Status__c,Apttus__Parent_Agreement__r.Apttus__Status__c from Apttus__APTS_Agreement__c where id in :Trigger.New AND Apttus__Status_Category__c = 'Terminated' ]; List 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 Apttus__APTS_Contract_From__c in: acc.keyset()]; system.debug(relagrmt); for(Apttus__APTS_Related_Agreement__c ag:relagrmt){

 //Apttus__APTS_Related_Agreement__c ar=new Apttus__APTS_Related_Agreement__c();
   //ar.Apttus__APTS_Contract_To__r.id=ag.Apttus__APTS_Contract_To__r.id;
ag.Apttus__APTS_Contract_To__r.CLM_Agreement_Termination_Date__c=acc.get(ag.Apttus__APTS_Contract_From__r.id);
    update ag;
    system.debug(ag);
    system.debug(ag.Apttus__APTS_Contract_To__r.CLM_Agreement_Termination_Date__c);
                system.debug(ag.Apttus__APTS_Contract_From__r.CLM_Agreement_Termination_Date__c);

      }    

} }

@Ayub , This is my modified trigger, now am getting date value @line no 11, debug logs giving all the records and my condition is also satified and giving Termination date as on Parent record. But I child record is not updating eventhough condition satisfied

0

You are initializing the related child object record having no value in any field

Apttus__APTS_Related_Agreement__c ar=new Apttus__APTS_Related_Agreement__c();

And then just after that, you are trying to access parent field's date even though this object is still blank:

 ar.Apttus__APTS_Contract_From__r.CLM_Agreement_Termination_Date__c
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.