function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Nitish KulkarniNitish Kulkarni 

Trigger before update problem

Can anyone please answer this question and explain


Q. A lead object has a custom feld Priorr_mailrrc. The following trigger is intended to copy
current email into the Priorr_mailrrc feld anytme the email feld is changed


trigger test on Lead (before update) {
for (Lead ld: trigger.new) {
if (ld._mail ! = trigger.oldMap.get(ld.id)._mail) {
ld.Priorr_mailrrc = trigger.oldMap.get(ld.id)._mail;
update ld;
}
}
}

Which type of excepton will this trigger cause?
a. A compile tme excepton
b. A null reference excepton
c. A DML exception
d. A Limit _excepton when doing a bulk update

Raj VakatiRaj Vakati
Complication error .. there is no _mail field on Lead 

Use this code
 
trigger test on Lead (before update) {
	for (Lead ld: trigger.new) {
		if (ld.email ! = trigger.oldMap.get(ld.id).email) {
			ld.Priorr_mailrrc__c = trigger.oldMap.get(ld.id).email;
		}
	}
}