function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
GWebberGWebber 

Variable does not exist Error

I'm new to VisualForce.  I've been following the tutorials, but I can't for the life of me get this variable declared properly it seems.  Anyone have an idea why it would think that opp doesn't exist as a variable?

 

 

public class RevenueProjectionController {
        public Opportunity opp { get; set; }
        
        public RevenueProjectionController()
        {
            opp = new Opportunity();
        }
        
        public static List<Opportunity> getEvents() {
                
                return [SELECT Id, Name, Account.Name 
                        FROM Opportunity
                        WHERE Event_Date__c >= :opp.Event_Date__c
                        ORDER BY Probability, Event_Date__c];
        }
        
        
        static testMethod void testCases() {
                List<Opportunity> test = new List<Opportunity>();
                test = getEvents();
        }
}

 

 

Best Answer chosen by Admin (Salesforce Developers) 
aballardaballard

Your static method getEvents is trying to access a member variable.   It can't do that.   You need to make it nonstatic, and create an object in the test method to invoke it on....

All Answers

aballardaballard

Your static method getEvents is trying to access a member variable.   It can't do that.   You need to make it nonstatic, and create an object in the test method to invoke it on....

This was selected as the best answer
GWebberGWebber

Thanks much sir.  Stupid issue, I know, but thanks for clearing it up for me!