Newer Version Available

This content describes an older version of this product. View Latest

Build and Release Your App with Metadata API

After developing and testing your app in a scratch org, you use the Metadata API to deploy the app to a sandbox. The sandbox mimics the release activity, commands, and process you plan to execute when you release your app to the production org.

To deploy Apex to production, unit tests of your Apex code must meet coverage requirements. Code coverage indicates how many executable lines of code in your classes and triggers are covered by your test methods. Write test methods to test your triggers and classes, and then run those tests to generate code coverage information.

Code coverage requirements must be met when you release an app to a production org. If you run tests with the release and review the results, you can meet these requirements.

If you don’t specify a test level when initiating a deployment, the default test execution behavior depends on the contents of your deployment package.
  • If your deployment package contains Apex classes or triggers, when you deploy to production, all tests are executed, except tests that originate from a managed package.
  • If your package doesn’t contain Apex components, no tests are run by default.

You can run tests for a deployment of non-Apex components. You can override the default test execution behavior by setting the test level in your deployment options. Test levels are enforced regardless of the types of components present in your deployment package. We recommend that you run all local tests in your development environment, such as a sandbox, before deploying to production. Running tests in your development environment reduces the number of tests required in a production deployment.