Salesforce: Iterate Map for old and new Value
Trigger
trigger Opportunitytrigger on Opportunity (Before Insert,Before Update,After Update) { //Before Update if(trigger.isBefore && trigger.isUpdate){ system.debug('--Before Update'); Opportunitytriggerhandler oOpportunitytriggerhandler = new Opportunitytriggerhandler(); oOpportunitytriggerhandler.onBeforeUpdate(Trigger.oldMap,Trigger.newMap); } } |
=============================================================
Handler Class
public class Opportunitytriggerhandler{
public void onAfterUpdate(map<id,Opportunity> oldMap,map<id,Opportunity> newMap){
public void onBeforeUpdate(map<id,Opportunity> oldMap,map<id,Opportunity> newMap){
OpportunityHelper objHelper = new OpportunityHelper();
objHelper.checkOpportunityAmount(oldMap,newMap);
}
}
=============================================================
Helper Class public class OpportunityHelper { public void checkOpportunityAmount(map<id,Opportunity> oldMap,map<id,Opportunity> newMap){ for(Opportunity opp:newMap.values()){ // Needs Analysis Qualification system.debug('Old AMount '+oldMap.get(opp.id).StageName); system.debug('New Map'+newMap.get(opp.id).StageName); System.debug('Before Update finish'); if(oldMap.get(opp.id).StageName != newMap.get(opp.id).StageName){ opp.isAmountChanged__c = true; } } } } |