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
nav anav a 

trigger.old fires when we are inserting records??

I am having a trigger with trigger.old.

While i am inserting records will trigger.old fires??
 
Vijay NagarathinamVijay Nagarathinam
HI,

Trigger.Old is null in a Before Trigger. You can't access the oldMap records, but you can access the oldMap records in Update trigger.

Thanks,
Vijay
Amit Chaudhary 8Amit Chaudhary 8
Please check below post to understand the context variable
1) http://amitsalesforce.blogspot.in/2015/10/trigger-context-variables.html

1) isExecuting Returns true if the current context for the Apex code is a trigger, not a Visualforce page, a Web service, or anexecuteanonymous() API call.
2) isInsert Returns true if this trigger was fired due to an insert operation, from the Salesforce user interface, Apex, or theAPI.
3) isUpdate Returns true if this trigger was fired due to an update operation, from the Salesforce user interface, Apex, or theAPI.
4) isDelete Returns true if this trigger was fired due to a delete operation, from the Salesforce user interface, Apex, or theAPI.
5) isBefore Returns true if this trigger was fired before any record was saved.
6) isAfter Returns true if this trigger was fired after all records were saved.
7) isUndelete Returns true if this trigger was fired after a record is recovered from the Recycle Bin (that is, after an undelete operation from the Salesforce user interface, Apex, or the API.)
8) new Returns a list of the new versions of the sObject records.Note that this sObject list is only available in insert and update triggers, and the records can only be modified in before triggers.
9) newMap A map of IDs to the new versions of the sObject records. Note that this map is only available in before update, after insert, and after update triggers.
10) old Returns a list of the old versions of the sObject records.Note that this sObject list is only available in update and delete triggers.
11) oldMap A map of IDs to the old versions of the sObject records.Note that this map is only available in update and delete triggers.
12) size The total number of records in a trigger invocation, both old and new.
 
DebadyutiDebadyuti
Hi Nav,

  Use this casetrigger code and debug it clears all your doubt .
trigger TriggeronCase on Case (before insert,after insert) {

 if(trigger.isbefore){
    
    system.debug('before old List data'+trigger.old);
    system.debug('before new List  data'+trigger.new);
    system.debug('before old map data'+trigger.oldmap);
    system.debug('before new map  data'+trigger.newmap);
 }
 
 if(trigger.isafter){
    
    system.debug('after old List data'+trigger.old);
    system.debug('after new List  data'+trigger.new);
    system.debug('after old map data'+trigger.oldmap);
    system.debug('after new map  data'+trigger.newmap);
 }      

}

The conclusion is :

 1) When we insert record and we have before trigger we will get 'null' for both  trigger.old, trigger.oldmap ,trigger.newmap [* map will be null in before insert as id is not assigned yet]
 2)When we insert record and we have after trigger we will get 'null' for trigger.old,trigger.oldmap[*There is no old instance] but we will get value in trigger.new and trigger.newmap