+ Start a Discussion

Insert Event and Trigger.new

Hi All,

           Can anybody tell me what is the difference in using Trigger.new with Before Insert and After Insert.In which condition

           Trigger.new used either with Before Insert or After Insert.Is any difference in the state of data during these two event?



        With Regards

        Prabhash Mishra

Shashikant SharmaShashikant Sharma

trigger.new can be used in both of the triggers before insert and after insert the only diffrence would be that you can not access Id field in before insert trigger.

Like in this trigger c.id will be nul in case of before insert trigger that means insertion is in progress and fields can be validated or altered using any logic. 


trigger testTrigger On Contact(before insert , after insert)
Set<ID> setContactId = Set<ID>();
for(Contact c : trigger.new)
if(c.id != null)

system.debug('Size of set '+ setContactId.size());


In this in case of before insetrt size will be 0 and in case of after insert size will be the number of items in trigger.new



With before insert u can use trigger.new to make changes to record. But with after insert u need to use update DML statement to make changes to the record.

ApeX trigger this might be of use