I am pretty new to development and I am trying to user Chris Aldridge's Lightweight Trigger Framework http://chrisaldridge.com/triggers/lightweight-apex-trigger-framework/.
I am looking to create a task related to the lead that was edited if the field value changed. Below is something that I tried and it didn't work. There is also some code that is commented out because it didn't work or I was trying different variations.
Does someone know how it should be written?
public static void AfterUpdate(Map<Id, SObject> newItems, Map<Id, SObject> oldItems) {
List<Task> newTasks = new List<Task>();
for (Lead updatedLead : (List<Lead>) newitems.values()) {
//SObject oldLead = oldItems.get(updatedLead.Id);
//SObject oldLeadValue = oldItems.values();
//Lead oldLead = Trigger.oldMap.get(updatedLead.ID);
//check to see if the product interest has changed. only want to create a task if the product
interest has changed.
if (updatedLead.ProductInterest__c != oldLead.ProductInterest__c)
{
//create a new task related to lead with product interest information
Task newTask = new Task(
Subject = 'Follow up with Lead, their Product Interest was updated',
Status = 'Not Started',
WhoId = updatedLead.Id,
OwnerId = updatedLead.OwnerId,
Priority = 'Normal');
//add this new task sObject to our list of tasks
newTasks.add(newTask);
}
} //end for loop
//insert the batch of new tasks into Salesforce
Insert newTasks;
} //end AfterUpdate method
Lead oldLead = (Lead)oldItems.get(updatedLead.Id);
?