I want to deploy a couple of apex classes and a apex trigger. Do i always have to trigger all the test execution?

Is there a way, where i dont trigger all but rather only the test classes related to the apex classes being deployed to production.

Running all 500 test classes takes 3hrs +


This option has been available since the Summer 15 release:

Choose Which Tests to Run in a Deployment

Test levels enable you to have more control over which tests are run in a deployment. To shorten deployment time to production, run a subset of tests when deploying Apex components. The default test execution behavior in production has also changed. By default, if no test level is specified, no tests are executed, unless your deployment package contains Apex classes or triggers. As part of this change, the runAllTests deployment option is now replaced with testLevel. You can choose which tests to run in a deployment by setting the desired test level. For a description of all test levels, see test levels for the deploy() call. In particular, to run a subset of tests in a deployment, set testLevel to the RunSpecifiedTests value and specify the tests to run in the runTests option.

When running a subset of tests, code coverage is computed for each class and trigger individually and is different than the overall coverage percentage. If your deployment package contains Apex classes and triggers, the executed tests must cover each class and trigger for a minimum of 75% code coverage.

If the code coverage of an Apex component in the deployment is less than 75%, the deployment fails. If one of the specified tests fails, the deployment also fails. We recommend that you test your deployment in sandbox first to ensure that the specified tests cover each component sufficiently. Even if your organization’s overall code coverage is 75% or more, the individual coverage of the Apex components being deployed can be less. If the code coverage requirement isn’t met, write more tests and include them in the deployment.

This change is in the Metadata API and is exposed in tools that are based on Metadata API, such as the Force.com Migration Tool.


  • 2
    The tricky part is when you need to deploy a test that may unintentionally trigger code in classes that won't get full coverage with a selected set of tests (e.g. utility classes). It takes a bit of practice to get it just right. – sfdcfox Apr 12 '18 at 2:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.