Print this page

Why do I get "Method does not exist" error if System or Test is used as class name without any namespace

Knowledge Article Number 000126959
Description

If we don't use the System namespace prefix, system static class names such as Test and System can be overridden by user-defined classes with the same name I.e. if you have created a class 'Test' and reference Test.startTest(); in any class (assuming startTest() method does not exist in 'Test')..
This can result in a compilation error 'Method does not exist'


 
Resolution As a best practice avoid using a naming convention where class names will be the same as System static classes such as Test and System.
If we have to name a class  Test  then ensure that any reference to system static classes are namespaced i.e. 'System.Test.startTest();' 
 

 





promote demote