Skip to main content
How to track the implementation of the trigger.new and trigger.old I am not getting a clear picture on this   . Anyone explain this example making the differences clear.  

trigger emailCheck on Employee__c (before update) 

{

    Map<Id,Employee__c> o = new Map<Id,Employee__c>();

    o = trigger.oldMap;

    for(Employee__c n : trigger.new)

    {

        Employee__c old = new Employee__c();

        old = o.get(n.Id);

        if(n.Email__c != old.Email__c)

        {

            n.Email__c.addError('Email cannot be changed');

        }

    }

}

Thanks and Regard

Rohit kumar singh
7 answers
  1. Jan 27, 2017, 6:39 AM
    Hi Rohit,

    The Trigger.New List contains the new record that is coming to the database and Trigger.Old list will hold the existing data that is already present in the database. In the above example the trigger is simply checking whether the email value that is coming into the database matches with the existing value. If it doesn't match then it will throw an error with the message "Email cannot be changed".

    Hope that makes sense !
0/9000