Stop running your entire test suite on every deploy — let Salesforce figure out which tests actually matter
If you've ever stared at a deployment progress bar while your entire 2,000-test suite runs because you changed one Apex utility method — this feature is for you. Introduces RunRelevantTests, a new test level that automatically analyzes your deployment and runs only the tests relevant to your code changes.
What Is RunRelevantTests?
Before this update, Apex deployments offered four test levels:
| Test Level | What it runs |
|---|---|
NoTestRun | No tests (sandbox only) |
RunSpecifiedTests | Only the tests you explicitly name |
RunLocalTests | All tests in your org (excluding managed packages) |
RunAllTestsInOrg | Every test including managed packages |
Adding a fifth option: RunRelevantTests. According to the official Salesforce Spring '26 Developer Guide, this new test level automatically analyzes your deployment and runs only the tests relevant to your code changes — which can dramatically speed up deployments in orgs with large test suites.
How to Use It
With Salesforce CLI
Pass RunRelevantTests as the --test-level flag on your deploy command:
That's the entire change to your workflow. Salesforce analyzes what you're deploying and determines which tests need to run — you don't need to specify anything else.
Fine-Grained Control with New Annotations
Also introduces two new @IsTest annotation parameters that give you explicit control over how individual test classes behave with RunRelevantTests.
@IsTest(critical=true)
Use this to mark a test that should always run, regardless of what's being deployed. This is useful for foundational tests that validate core business logic across your entire org.
@IsTest(testFor='ApexClass:MyClass')
Use this to explicitly tell Salesforce which component a test class is associated with. The test runs only when that specified component is modified in the deployment.
critical=true as your safety net — tests that must always pass no matter what. Think of testFor as your precision scalpel — telling Salesforce exactly which class a test belongs to so the relevance analysis is accurate even when it can't infer the relationship automatically.Gotchas to Watch Out For
RunRelevantTests is subject to the Salesforce Beta Services Terms. Test thoroughly in a sandbox before using this in any production deployment pipeline.RunRelevantTests changes which tests run, not the coverage requirements. Your org still needs to meet the 75% Apex code coverage threshold for production deployments. If the relevant tests don't cover enough of your code, the deployment will fail.@IsTest(testFor='ApexClass:MyClass') explicitly helps the analysis be more accurate.critical=true for cross-cutting testsIf you have tests that validate things like triggers, sharing rules, or platform events that are affected by many types of changes, mark them critical=true to ensure they're never accidentally skipped.Summary & Key Takeaways
RunRelevantTests Quick Reference- New test level:
RunRelevantTests— automatically runs only tests relevant to your deployment's code changes - CLI usage:
sf project deploy start --test-level RunRelevantTests @IsTest(critical=true)— forces a test to always run regardless of what's deployed@IsTest(testFor='ApexClass:MyClass')— explicitly links a test class to a specific component- Test in sandbox before using in production pipelines
- Code coverage requirements (75% for production) still apply
For large orgs with hundreds of Apex classes and thousands of tests, RunRelevantTests has the potential to significantly cut down the feedback loop on deployments. Start by enabling it in sandbox, annotate your critical tests with critical=true, and let Salesforce do the analysis work for you.
📄 Sources: Salesforce Developer's Guide to the Spring '26 Release | Spring '26 Release Notes — Run Relevant Tests


0 Comments