[SalesForce] how to pass the map from one method to onother method

I have trigger after insert and after update

if(trigger.isinsert){
Forecastcheckemail fr=new Forecastcheckemail(trigger.newmap,null);
fr.SendEmail();
}
If(trigger.Isupdate)
{
Forecastcheckemail fr=new Forecastcheckemail(trigger.newmap,trigger.oldmap);
fr.SendEmail();
}

Apex Class:

enter image description here

I want newOppMap in sendEmail() Method as well.
But i am getting error in the line Opportunity opp = newOppMap.get(id);…..Please suggest

Best Answer

You can simply pass the new map in fr.SendEmail(); method

fr.SendEmail(Trigger.NewMap);

and your method will be

public void SendEmail(map<Id, Opportunity>){

}

Or Another way use a private map in the controller to store the new map and old map and when you controller constructor called. Just assign the old and new map to private variables and use those variables in wherever you want

Related Topic