Skip to main content

Test Methods with Full Data Access

David Martin avatar
Written by David Martin
Updated this week

Overview

This rule identifies test methods that use the @IsTest(seeAllData=true) annotation, which allows tests to access real org data instead of operating in a fully isolated test context. While Salesforce supports this annotation, relying on it introduces long term maintenance risks and reduces the reliability of your test suite.

Code reviews classifies this as a Error, since tests that depend on actual org data may behave inconsistently across environments and fail when data changes unexpectedly. Following best practices, test methods should create the data they need rather than relying on existing records.

Why This Matters

Test isolation is essential for ensuring stable, predictable, repeatable test execution. When a test is allowed to access real org data:

  • Test results become dependent on the environment

  • Data changes in production or sandboxes can cause tests to pass or fail unpredictably

  • Deployment pipelines may break due to missing or altered records

  • Debugging becomes significantly more difficult due to hidden dependencies

By avoiding seeAllData=true, tests remain self contained and reliable across all orgs, environments, and timeframes.


What Triggers This Rule

This rule flags any test method or test class that uses:

@IsTest(seeAllData=true)

The rule does not analyze whether the test could run successfully without this annotation, its purpose is to surface potential risk areas so teams can modernize their test patterns and avoid environment dependent failures.

Even if your use of the annotation is intentional, Code reviews will flag it to encourage review and to promote adherence to Salesforce’s recommended testing practices.

Recommended Approach

To avoid unintended dependencies on org data and ensure strong test isolation:


Remove seeAllData=true whenever possible

Rewrite tests so they do not rely on existing records:

@IsTest
private class ExampleTest {
@IsTest
static void testLogic() {
Account acc = new Account(Name = 'Test');
insert acc;
// test logic using acc
}
}

Create all required data inside the test

Use the @TestSetup method where data is shared across tests.

Only use seeAllData=true as a last resort

Some legacy implementations or metadata-dependent features may require it, but these cases should be rare and well documented.

Summary

Tests that use @IsTest(seeAllData=true) access real org data, reducing test isolation and increasing fragility. This rule warns when such tests are detected, encouraging developers to follow Salesforce best practices: create required test data within the test itself and avoid relying on environment specific records. Removing data dependencies leads to more stable, predictable, and maintainable tests across all environments.

Did this answer your question?