---
schema_version: "1"
id: 227a584d2e2ab6bc5e279836ad75ad6b5625e47836fcdb38c24dd019bc6168e0
title: Deploy Apex Components Faster by Running Only Relevant Tests (Beta)
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/release-notes/260-0-0/rn_apex_run_relevant_tests.md
canonical_url: https://help.salesforce.com/s/articleView?id=release-notes.rn_apex_run_relevant_tests.htm&release=260&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 5d9adce41cc6e9794c3b83f1822bf90382f99ee59fd00527717c0779f3ed3179
description: To reduce Apex component deployment time, use the new RunRelevantTests test level to run only the tests relevant to your code changes. This feature automatically determines which tests to run based on an analysis of the deployment payload and the payload dependencies. For fine-grained control, you can annotate test classes so that they either run regardless of the deployment payload, or run when specified components are new or modified. This targeted approach boosts the speed and reliability of your deployment while maintaining code quality and coverage requirements.
products:
  - Cross Cloud Packages Solutions
release: "260"
---
# Deploy Apex Components Faster by Running Only Relevant Tests (Beta)

To reduce Apex component deployment time, use the new `RunRelevantTests` test level to run only the tests relevant to your code changes. This feature automatically determines which tests to run based on an analysis of the deployment payload and the payload dependencies. For fine-grained control, you can annotate test classes so that they either run regardless of the deployment payload, or run when specified components are new or modified. This targeted approach boosts the speed and reliability of your deployment while maintaining code quality and coverage requirements.

**Where:** The `RunRelevantTests` test level is available in all API versions. The `@IsTest(critical=true)` and `@IsTest(testFor='...')` annotations are available in API version 66.0 and later. The feature is available in Lightning Experience and Salesforce Classic in Enterprise, Performance, Unlimited, and Developer editions.

![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-salesforce_release_notes-260-0-0-production-enus/ba62a63b-6cd1-440e-8d24-e867afab0363/images/icon_note.png)

Note The `RunRelevantTests` test level and the associated `@IsTest()` annotations are pilot or beta services that are subject to the Beta Services Terms at [Agreements — Salesforce.com](https://www.salesforce.com/company/legal/) or a written Unified Pilot Agreement if executed by Customer, and applicable terms in the [Product Terms Directory](https://ptd.salesforce.com/). Use of these pilot or beta services are at the Customer’s sole discretion.

**Why:** The new `RunRelevantTests` test level addresses the limitations of the existing `RunLocalTests` and `RunSpecifiedTests` test levels. `RunLocalTests`, the default test level for Apex production deployments, runs all Apex tests in the org except the ones that originate from installed managed and unlocked packages. In orgs with extensive test suites, `RunLocalTests` can result in long deployment times even for small changes. In contrast, `RunRelevantTests` runs only Apex tests relevant to modified components in the deployment payload, so the number of tests that run scales proportionally to the deployment size. `RunRelevantTests` also addresses a drawback of the `RunSpecifiedTests` test level. With `RunSpecifiedTests`, you must manually determine which tests are applicable to the changes, which often requires custom DevOps tooling. In contrast, the `RunRelevantTests` test level engine analyzes the deployment payload and automatically runs a subset of tests based on that analysis.

**How:** To specify the `RunRelevantTests` test level when you deploy Apex components, use one of these methods.

- To deploy by using a [file-based call](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_deploy.htm), set the `testLevel` field on the `DeployOptions` object to `RunRelevantTests`. Then pass `DeployOptions` as an argument to the `deploy()` method.
- To deploy by using the [`deployRequest`](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_rest_deploy.htm) REST resource, define a `deployOptions` object in the POST request body and set its `testLevel` field to `RunRelevantTests`.
- To deploy by using the Salesforce CLI, use the [`sf project deploy start`](https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_project_commands_unified.htm) command and set the `--test-level` flag to `RunRelevantTests`.

If a test class must always run regardless of the classes or triggers in the deployment payload, annotate the test class with `@IsTest(critical=true)`.

If a test class must always run whenever specified classes or triggers are new or changed in the deployment payload, annotate the test class with `@IsTest(testFor='ApexClass:ClassName, ApexTrigger:TriggerName')`.

#### See Also

- [_Metadata API Developer Guide_: Run Relevant Apex Tests in a Deployment (Beta)](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_deploy_run_relevant_tests.htm)
- [_Metadata API Developer Guide_: deploy()](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_deploy.htm)
- [_Apex Developer Guide_: IsTest Annotation](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_isTest.htm)
- [_Salesforce CLI Command Reference_: project Commands](https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_project_commands_unified.htm)