Trigger.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.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_context_variables_considerations.htm
Trigger.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.
For more info go through this link:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_context_variables.htmhttps://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_context_variables_considerations.htm
Suppose you have a custom object 
Custom_obj__cTrigger.new means it is a List<Custom_obj__c>
and
Trigger.newMap means it is a map<Id, Custom_obj__c>
In before insert context your 
Trigger.newMap always be null because in before context records is not submitted to database so Id is not generated that's why in before insert we don't use Trigger.newMap
But in After insert Id is generated so We can use 
Trigger.newMap
In case of before and After update since id is already generated in Insert event.
So we can use 
Trigger.newMap in before and After update
No comments:
Post a Comment