How to compare old field value with the next field value 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 :
        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');


No comments:

Post a Comment

Sharing is Caring!!! Share this with your friends!!!

submit to reddit