2

I have a question about the two examples shown below as it seems that a testMethod defined within a standard class defaults SeeAllData to true whereas when the test method is defined in a separate class and SeeAllData is not set it will default to false.

Has anyone else come across this or could shed some light on documentation of this functionality? in the examples and documentation i have looked at i have seen the following.

The isTest annotation on methods is equivalent to the testMethod keyword.

Recently an issue came up which would suggest that testMethod defaults SeeAllData differently in certain circumstances.

Approach A)

Public class ObjectTriggerHandler{

    public void foo(){
    //do something here
    }

    static testMethod void testFoo(){
    //Test code here
    }
}

vs

Approach B)

Public class ObjectTriggerHandler{

    public void foo(){
    //do something here
    }
}

and

@isTest
private class ObjectTriggerHandlerTest{

    static testMethod void testFoo(){
    //Test code here
    }
}
4

As Keith C has already mentioned, it depends on the API version your test class is saved in. If your class is using API version 23 or lower, than it will default to seeAllData=true.

From the above mentioned URL:

Test code saved using Salesforce.com API version 23.0 or earlier continues to have access to all data in the organization and its data access is unchanged.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.