+ Start a Discussion
Surender reddy SalukutiSurender reddy Salukuti 

variable doesnot exist


i wrote this in appexclass
public class Trigger_Opportunity_Handler{
    public static void afUpdate(map<Id,Opportunity>  oldMap, map<Id,Opportunity>  newMap){
        set<id> optyids=oldMap.keyset();
        User u=[select id from User where alias='udemo'];
           list<OpportunityTeamMember> teams=new list<OpportunityTeamMember>(); 
        for(Id key:optyIds){
            Opportunity old=oldMap.get(key);
            Opportunity optyNew=newMap.get(key);
            if(old.StageName!='Closed Won'&&optyNew.StageName=='Closed Won'){
                OpportunityTeamMember ot=new OpportunityTeamMember();
                ot.TeamMemberRole='Account Manager';
        insert teams;
Variable does not exist: StageName
Meghna Vijay 7Meghna Vijay 7
Are you getting this error in dev console or when you are performing DML operations?

Surender reddy SalukutiSurender reddy Salukuti
Hi thanks for replay. I am writing in developer console.
Hi Surender,

Update the below code to
if(old.StageName!='Closed Won'&&optyNew.StageName=='Closed Won'){ TO
//Remove these 2 lines
//Remove Opportunity old=oldMap.get(key);
//Remove Opportunity optyNew=newMap.get(key);
if(oldMap.get(key).StageName!='Closed Won'&&newMap.get(key).StageName=='Closed Won'){

Map.get(key) Returns a Reference to the Record. Please find the documentation here : https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_map.htm

Please mark this as SOLVED if it had helped you. Thanks!

Krishna Avva