RunRelevantTests: Faster Salesforce Deployments, With a Catch
Salesforce's new test level runs only the tests your deployment needs. It is still in beta, and it can miss tests your org depends on. Here is what it does, how to turn it on, and where it can miss.
You change one Apex class. You deploy to production. Then you wait while every local test in the org runs.
In a big org, that wait can take a long time. It also slows down every fix you need to ship.
Salesforce now has a new answer: the RunRelevantTests test level. It is still in beta. Here is what it does, how to turn it on, and where it can miss.
What changed
RunRelevantTests is a new test level for deployments. Salesforce looks at what is in your deployment and what it depends on. Then it runs only the tests that matter for that change.
A small deployment runs a small set of tests. A large deployment runs more.
It arrived as a beta in Spring '26. The current Metadata API guide (opens in a new tab) still labels it beta, and beta terms apply.
How it compares to the options you know
| Test level | Who picks the tests | Trade-off |
|---|---|---|
| RunLocalTests (production default) | Salesforce runs all local tests, except tests from installed managed and unlocked packages | Safe, but slow in orgs with big test suites |
| RunSpecifiedTests | You list the tests yourself | Fast, but you must know which tests matter. Teams often build custom tooling for this |
| RunRelevantTests (beta) | Salesforce picks, based on the payload and its dependencies | Fast, less DevOps work, but the engine can miss tests |
In short: RunRelevantTests aims for the speed of RunSpecifiedTests without the manual work.
The coverage rule does not go away
You still need at least 75% code coverage. The rule is per class and per trigger in the deployment. It is checked for each one on its own, not as an org-wide average.
If a class falls short, you can use the new annotations below to pull in more tests.
How to turn it on
You set the test level the same way you set any other test level:
- Metadata API (SOAP): set
testLeveltoRunRelevantTestsonDeployOptions, then pass it todeploy(). - REST deploy: set it on the
deployOptionsobject in the request body. - Salesforce CLI: set the
--test-levelflag on a supported project command.
sf project deploy start --test-level RunRelevantTests
Two new @IsTest options
Salesforce added two options so you can steer the engine. Both work only at the class level, from API version 66.0. Putting them on a test method causes a compile error. See the IsTest annotation reference (opens in a new tab) for the full syntax.
1. critical=true: always run this class
A critical test class runs in every RunRelevantTests deployment, no matter what is in the payload. Use it for your safety net tests.
@IsTest(critical=true)
private class OrgSafetyNetTest {
@IsTest
static void coreProcessStillWorks() {
// test body
}
}
Use it sparingly. Every critical class adds time to every deployment. Mark too many and you lose the speed you came for.
2. testFor: run this class when these components change
testFor ties a test class to specific classes or triggers. When any of them is new or changed in the deployment, the tests run.
The value is a comma-separated string. Use ApexClass:Name for classes and ApexTrigger:Name for triggers. For another namespace, use the full name, like ApexClass:MyNamespace.ClassName.
@IsTest(testFor='ApexClass:AccountHandler, ApexTrigger:AccountTrigger')
private class AccountHandlerTest {
@IsTest
static void updatesRating() {
// test body
}
}
Where it can miss
This is the catch. Salesforce says the engine picks tests from the compile-time dependency graph. Some links only exist at run time, so the engine cannot see them:
- Classes created by name, for example with
Type.forName. - Dependency injection or other dynamic dispatch patterns.
- Custom metadata driven handler frameworks that load classes this way.
If your org uses these patterns, a test that should run may be skipped. The deployment can pass while a real break goes out.
Early beta testing by Salesforce MVP Keir Bowden (Bob Buzzard (opens in a new tab)) found more gaps, in a pre-release org in January 2026:
- Tests further down a dependency chain were not picked. Only tests with a direct link to the changed class ran.
- The deployment status page was hard to read. The CLI
--jsonoutput was the clear way to see which tests ran.
Those findings came from a very early build. Treat them as things to check in your own org, not as fixed facts.
What I would do now
- Keep it out of production pipelines for now. Salesforce's own blog (opens in a new tab) says not to integrate the beta into production pipelines yet. Keep a full local test run before any production release.
- Try it in sandbox and CI first. Use it for dev and QA deployments, where speed matters and risk is low.
- Compare test lists. Run the same change with RunLocalTests and RunRelevantTests. Check which tests the engine skipped, and why.
- Tag dynamic code today. Find classes built with
Type.forName, injection, or metadata driven handlers. AddtestForto the tests that cover them. This work pays off when the feature goes GA. - Pick a short critical list. Choose a few tests that guard core business processes. Mark only those as critical.
The bigger point
RunRelevantTests is only as good as your org's dependency picture. If no one on your team knows what calls what, the engine will not know either.
The teams that get the most from this feature will be the ones that already map their dependencies and keep their test classes clean. Our dependency graph series covers what that map looks like and how to keep it true.