+ Start a Discussion
Starz26Starz26 

Getter bug - Is this normal

Ok. In the first class, I am following the usual pattern for a getter however the returned value is ALWAYS NULL. If I debug in the last line of the if statement the oppQualifiedDate is set, but dubugging right before the return it is null:

 

    public map<ID,Date> oppQualifiedDate{
    
        get{
            //system.debug(logginglevel.error,opps);        
            if(oppQualifiedDate == null){
                //For some reason if I do not do it this way, oppQualified date is always returned as null
                Map<ID,Date> oppQualifiedDate = New Map<ID,Date>();

                for(OpportunityHistory oh : [Select OpportunityID, StageName, CreatedDate, CloseDate 
                                            From OpportunityHistory 
                                            Where OpportunityID IN :opps.keySet()
                                            ORDER BY OpportunityID, StageName ASC]){
                
                    if(oppQualifiedDate.containsKey(oh.OpportunityID))
                        continue;
                    
                    if(oh.StageName.left(1).isNumeric()){
                        if(integer.valueOf(oh.StageName.left(1)) > 1)
                            oppQualifiedDate.put(oh.OpportunityID,oh.createdDate.date());
                            
                    }                            

                }
//This has the appropriate values set               
system.debug(logginglevel.error,oppQualifiedDate);                                                                                               
            }
//Here it is now null            
system.debug(logginglevel.error,oppQualifiedDate);                                                                                   
            return oppQualifiedDate;
        
        }
        
        private set;
    
    
    
    }

 

Now, if I use a tmp variable to set the map and then set oppQualifiedDate to that variable the return value is correct....

 

    public map<ID,Date> oppQualifiedDate{
    
        get{
            //system.debug(logginglevel.error,opps);        
            if(oppQualifiedDate == null){
                //For some reason if I do not do it this way, oppQualified date is always returned as null
                Map<ID,Date> tmp = New Map<ID,Date>();

                for(OpportunityHistory oh : [Select OpportunityID, StageName, CreatedDate, CloseDate 
                                            From OpportunityHistory 
                                            Where OpportunityID IN :opps.keySet()
                                            ORDER BY OpportunityID, StageName ASC]){
                
                    if(tmp.containsKey(oh.OpportunityID))
                        continue;
                    
                    if(oh.StageName.left(1).isNumeric()){
                        if(integer.valueOf(oh.StageName.left(1)) > 1)
                            tmp.put(oh.OpportunityID,oh.createdDate.date());
                            
                    }                            

                }
                oppQualifiedDate = tmp;
system.debug(logginglevel.error,oppQualifiedDate);                                                                                               
            }
            system.debug(logginglevel.error,oppQualifiedDate);                                                                                   
            return oppQualifiedDate;
        
        }
        
        private set;
    
    
    
    }

 

It this normal? Why would I have to set the oppQualifiedDate to a temporary variable for it to properly be returned?

 

 

levaleva

just a hunch. I noticed your setter is private, try making it public 

Starz26Starz26

no dice