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
ifthikar Ahmed 1ifthikar Ahmed 1 

trigger.old clarification

can we use trigger.old in after insert event ???

More over, my code is to create a new invoice record when the "active checbox" is selected true in the coustomer obj and the old value shuld be unchecked. event has to update evvent where in my trigger works fine in  after Insert how come pls explain

trigger test1 on Apex_Customer__c (after Insert) {
   list <APEX_Invoice__c> upinv = new list <APEX_Invoice__c>();
   for(Apex_Customer__c newcus : trigger.new)
   {
       
       
       if(newcus.APEX_Active__c == True && trigger.oldmap.get(newcus.id).APEX_Active__c != True )
       {
           APEX_Invoice__c newinv = new APEX_Invoice__c();
           newinv.APEX_Customer__c = newcus.Id;
           upinv.add(newinv);
       }
   }
insert upinv;
}
Dhanya NDhanya N
Hi,

We can not use trigger.old in after insert event. It returns null as there is no old instance.
Take a look on trigger context variable (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_context_variables.htm)

Thanks,
Dhanya