During a merge of leads I'm trying to combine the descriptions from the old leads.
In the Trigger.isDelete section, my variable newLeadDescription variable receives all the old descriptions added together.
But when I try to use the updated newLeadDescription in the Trigger.isUpdate of my code, newLeadDescription still equals ''
.
How do I globally update newLeadDescription?
trigger MergeLeadDescriptions on Lead (before delete, before update) {
List<String> leadDescriptions = new List<String> ();
String newLeadDescription = '';
if (Trigger.isDelete) {
Integer i = 0;
if (Trigger.isBefore) {
for(Lead o : Trigger.Old) {
leadDescriptions.add(o.Description);
System.debug('The old lead description is ' + leadDescriptions[i]);
newLeadDescription = newLeadDescription + ' ' + leadDescriptions[i];
System.debug('Current newLeadDescription value is ' + newLeadDescription);
i++;
}
}
}
else if (Trigger.isUpdate) {
if (Trigger.isBefore) {
for(Lead n : Trigger.New) {
//n.Description = n.Description + ' ' + newLeadDescription;
System.debug('Current newLeadDescription in this scope is ' + newLeadDescription);
System.debug('The new lead description is ' + n.Description);
}
}
}
}