I have object called Agreement. One agreement will have mutliple child agreements. we have a Parent Agreement lookup field on Child Agreement with Parent agreement value.
When Status category of Child agreement is Terminated, then on Parent agreement Status category and Termination date should be updated as child record.
The issue is am not getting Parent id from my trigger. So its not updating on Parent record eventhough my if condition satisfied.
Class:
public class UpdateTerminationDate {
public static Boolean isFirstTime = true;
}
Trigger:
trigger UpdateTerminationDateTrigger on Apttus__APTS_Agreement__c (after insert,after update) {
public static Boolean bool = true;
If(UpdateTerminationDate.isFirstTime){
UpdateTerminationDate.isFirstTime = false;
List<Apttus__APTS_Agreement__c> agr=new List<Apttus__APTS_Agreement__c>();
List<id> acc=new List<id>();
for(Apttus__APTS_Agreement__c a:Trigger.New)
{
acc.add(a.id);
system.debug(acc);
}
List<Apttus__APTS_Agreement__c> 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: acc];
for(Apttus__APTS_Agreement__c ag:agreement){
system.debug(ag.Apttus__Parent_Agreement__r.CLM_Agreement_Termination_Date__c);
if(ag.Apttus__Status_Category__c=='Terminated')
{
ag.Apttus__Parent_Agreement__r.CLM_Agreement_Termination_Date__c=ag.CLM_Agreement_Termination_Date__c;
//ag.Apttus__Status_Category__c=ag.Apttus__Parent_Agreement__r.Apttus__Status_Category__c;
//ag.Apttus__Status__c='Terminated';
system.debug('test');
system.debug(ag.Apttus__Parent_Agreement__r.CLM_Agreement_Termination_Date__c);
system.debug(ag.CLM_Agreement_Termination_Date__c);
agr.add(ag);
}
update ag;
}
update agr;
system.debug(agr);
}
}
Isuue is both agr id and ag id are same(child agreement id)