Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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
    }
}
share|improve this question
3  
AFAIK the driving factor is the API version. The details are described in Isolation of Test Data from Organization Data in Unit Tests. –  Keith C Jul 16 at 11:04
    
Thanks Keith, looking at the class in question it is running SF API 12 which would explain the issue here. –  Michael Fleming Jul 16 at 11:13
add comment

1 Answer 1

up vote 4 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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