Activity Forums Salesforce® Discussions Why can you not use Trigger.newMap in beforeInsert Salesforce trigger?

  • Nikita

    Member
    August 14, 2019 at 4:23 am

    Hi Piyush,

    In before insert context your Trigger.NewMap will always be null because in before context records are not submitted to the database, so the Id is not generated yet. 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

  • Saddam

    Member
    August 14, 2019 at 6:32 am

    Hi Piyush

    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 useTrigger.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

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos