I am trying to understand how I can compare the the old and new values of the fields in the Apex Class. I have a VF page on Leads object which has the inputCheckbox. From the VF pages's extension controller I am updating the Lead record which fires the after update trigger on the Lead record which inturn calls the apex Class. The Apex Class is like below
Public class LeadTriggerHandler{
public static void updateAOI(set<Id> lIds){
List<Lead> Leadlist = [Select Id, Autoimmune__c ,Immunology__c
from Lead WHERE Id IN: lIds];
List<Lead> updateList = new List<Lead>();
set<id> LeadIds= new set<Id>();
for(Lead l : Leadlist){
if(l.Autoimmune__c == True)
{
l.Immunology__c = true;
if(!leadIds.contains(l.Id)){
leadIds.add(l.Id);
updateList.add(l);
}}}
checkRecursiveTrigger.ranOnce = true;
if(!updatelist.isempty())
update updatelist;
}}
In the Apex Class I should check if the Autoimmune__c
new value is True I need to do something and new value of the field is false I should be do something else. I was reading how how I can do the comparison of the old and new values in apex class and found that cloning the orginal record. can anyone suggest if I need to handle this in the Trigger or Apex Class or VF page. The trigger is like below where we call the apex class with the list of the Lead ID's
trigger LeadTrigger on Lead (after insert, after update) {
set<Id> leadIds = new set<Id>();
for(Lead l : Trigger.new){
leadIds.add(l.Id);
}
if(!leadIds.isempty() && checkRecursiveTrigger.ranOnce == false)
LeadTriggerHandler.updateAOI(leadIds);
}
Any help is greatly appreciated