anusha(salesforce developer)

Thursday, 15 September 2016

Trigger.old example in Salesforce

Trigger.old example in Salesforce

Sample Trigger:

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');
        }
    }
}


Output:

No comments:

Post a Comment