Newer Version Available
Using the isTest(SeeAllData=true) Annotation
Annotate your test class or test method with IsTest(SeeAllData=true) to open up
data access to records in your organization.
This example shows how to define a test class with the @isTest(SeeAllData=true) annotation. All the test
methods in this class have access to all data in the
organization.
This second example shows how to apply the @isTest(SeeAllData=true) annotation on a test
method. Because the test method’s class isn’t annotated, you have to annotate the method
to enable access to all data for the method. The second test method doesn’t have this
annotation, so it can access only the data it creates. In addition, it can access
objects that are used to manage your organization, such as
users.
- Considerations for the @IsTest(SeeAllData=true) Annotation
-
- If a test class is defined with the @isTest(SeeAllData=true) annotation, the annotation applies to all its test methods whether the test methods are defined with the @isTest annotation or the (deprecated) testMethod keyword.
- The @isTest(SeeAllData=true) annotation is used to open up data access when applied at the class or method level. However, if the containing class has been annotated with @isTest(SeeAllData=true), annotating a method with @isTest(SeeAllData=false) is ignored for that method. In this case, that method still has access to all the data in the organization. Annotating a method with @isTest(SeeAllData=true) overrides, for that method, an @isTest(SeeAllData=false) annotation on the class.
- @isTest(SeeAllData=true) and @isTest(isParallel=true) annotations cannot be used together on the same Apex method.