How to compare old field value with the New field value in Salesforce?
Here you can compare the values with trigger.oldMap . Here is the sample example on contact email field.
trigger Email_Check_On_Contact on Contact (before update) {
Map<Id,Contact> o = new Map<Id,Contact>();
o = trigger.oldMap;
for(Contact newcont: trigger.new)
{
if(newcont.Email != o.get(newcont.Id).Email)
{
newcont.Email.addError('Email cannot be changed');
}
}
}
0 comments:
Post a Comment