Skip to main content
1 Antwort
  1. 21. Juni 2014, 14:10
    Example

     

    trigger BeforeInsertTrigger on Account (before insert) {

    set<id> sid = new set<id>();

    for(Account A :trigger.new){

    sid.add(A.Id);

    system.debug('sid :'+sid);

    //This line of code would raise Null Pointer Exception becasue trigger.newMap dont work for before trigger.while Sid will Contain all Ids of records.

    //If you are using after insert this trigger.newMap would return you the Objects Values in Acc.

    Account Acc = trigger.newMap.get(A.Id);

    system.debug('Acc :'+Acc);

    }

    }

    Note : If you are setting event after insert then this will not raise error it will let you have all data with all Ids in Acc.

     

    Account Acc = trigger.newMap.get(Acc.Id);

     

    Now you have All record field value in Acc object.

     

    Documentation reads

     

    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.

     

    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.
0/9000