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
Clap MasterClap Master 

Accessing static fields from a test class

I'm trying to access static fields of a class from within a test class, with a statement like this:

 

genericObject.genericField = outerClass.staticVariable;

 

And the Force IDE is telling me 'Variable does not exist' when I try and execute the test.  I'm not able to find anything about special considerations when accessing static class members within tests.  Am I doing something fundamentally wrong here?

Best Answer chosen by Admin (Salesforce Developers) 
Clap MasterClap Master

So it appears that test cases you run locally still somehow look to the server for other classes?  Something like that ... after I removed all my compile errors from my test class and saved the whole project to the server, it ran fine.

All Answers

8hrWait8hrWait

Hi,

 

Please check if the 'genericField' is static as well.

 

Thanks.

SammyComesHereSammyComesHere

public ??

8hrWait8hrWait

Declaring the variable as 'static varName' should be fine. You can make the variable as 'public' as well - should not be a problem.

 

Clap MasterClap Master

So it appears that test cases you run locally still somehow look to the server for other classes?  Something like that ... after I removed all my compile errors from my test class and saved the whole project to the server, it ran fine.

This was selected as the best answer
SammyComesHereSammyComesHere

lol that doesnt happen