Activity Forums Salesforce® Discussions When to use newMap and oldMap in Salesforce?

  • Sumit

    Member
    April 29, 2020 at 1:50 pm

    Trigger.OldMap: Trigger.oldMap returns map of old records which are updated with new values. These List of records already there in Database. Trigger.oldmap available in Before update, after update, Before Delete and After Delete triggers.
    Trigger.NewMap: Trigger.newMap returns map of new records which are trying to insert into Database. This is available in Before Insert, Before Update, After Insert, After Update Triggers and undelete Triggers. This list of records can only modified in Before triggers.

  • Shweta

    Member
    April 29, 2020 at 1:56 pm

    Trigger.newMap: It is a map with key as ID of the record and value as the record itself. In case of accounts when we say trigger.newMap we are talking about a map of key-value pairs where the key is the account ID and the value is the account record itself.
    Trigger.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.

  • Ayush

    Member
    April 30, 2020 at 8:23 am

    Trigger.oldmap available in Before update, after update, Before Delete and After Delete triggers.
    Trigger.newMap This is available in Before Insert, Before Update, After Insert, After Update Triggers and undelete .

  • Marziya

    Member
    April 30, 2020 at 11:32 am

    when we say trigger.newMap we are talking about a map of key-value pairs where the key is the account ID and the value is the account record itself.
    Trigger.OldMap: A map of IDs to the old versions of the sObject records.

Log In to reply.

Popular Salesforce Blogs