You need to sign in to do that
Don't have an account?
Arpita Nayak
trigger.old example
Hi can any one explain this code .If required please simplify the code also.
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');
}
}
}
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');
}
}
}
Let us know if this will help you
All Answers
Please check the below code along with comments.
I also simplified the code:
Please do let me know if it helps you.
Regards,
Mahesh
So, basically, its a trigger that disables users to edit the email.
Let us know if this will help you
1) http://amitsalesforce.blogspot.in/2015/10/trigger-context-variables.html
2) http://amitsalesforce.blogspot.in/2015/06/trigger-best-practices-sample-trigger.html
Trigger.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.