Stop running your entire test suite on every deploy — let Salesforce figure out which tests actually matter

⚠️ Beta feature: RunRelevantTests is available as a Beta feature and is subject to the Salesforce Beta Services Terms. Not recommended for production deployments without thorough sandbox testing.

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 LevelWhat it runs
NoTestRunNo tests (sandbox only)
RunSpecifiedTestsOnly the tests you explicitly name
RunLocalTestsAll tests in your org (excluding managed packages)
RunAllTestsInOrgEvery 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:

Bash
sf project deploy start --test-level RunRelevantTests

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.

Apex
@IsTest(critical=true)
private class AccountValidationTest {
    @IsTest
    static void testCriticalBusinessRule() {
        // This test always runs, no matter what is being deployed
    }
}

@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.

Apex
@IsTest(testFor='ApexClass:OpportunityService')
private class OpportunityServiceTest {
    @IsTest
    static void testCloseOpportunity() {
        // Only runs when OpportunityService is part of the deployment
    }
}

💡 How these two annotations work togetherThink of 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

⚠️ 1. This is a Beta featureAs stated in the official release notes, RunRelevantTests is subject to the Salesforce Beta Services Terms. Test thoroughly in a sandbox before using this in any production deployment pipeline.
⚠️ 2. Production deployments still require 75% code coverageRunRelevantTests 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.
⚠️ 3. Relevance analysis is automatic — but not magicSalesforce determines relevance by analyzing the components in your deployment. If a test class has an unclear or indirect relationship to a changed class, adding @IsTest(testFor='ApexClass:MyClass') explicitly helps the analysis be more accurate.
⚠️ 4. Use 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

 If you have any question please leave a comment below.

If you would like to add something to this post please leave a comment below.
Share this blog with your friends if you find it helpful somehow !

Thanks