2

How do you declare a static method inside with another static method? Is it possible? Why are test class methods always static? Can anyone guide me?

  • Hi there, welcome to the site! Please refrain from posting multiple similar questions—this will not get you an answer any faster and duplicates will be removed. – Matt Lacey Aug 2 '16 at 23:32
4

You CANNOT declare a static method inside of another static method. That's simply one of the rules of APEX and is clearly stated in the docs here.

Note that An inner class behaves like a static Java inner class, but doesn’t require the static keyword. An inner class can have instance member variables like an outer class, but there is no implicit pointer to an instance of the outer class (using the this keyword).

Test methods are always static void. A static method is used as a utility method, and it never depends on the value of an instance member variable. Because a static method is only associated with a class, it can’t access the instance member variable values of its class. Test methods are void because they never return anything. This combination is well suited to test classes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy