Before deploying Apex code to a Salesforce production or sandbox environment, it is critical to accurately assess the current state of code coverage in the destination org. Inaccurate coverage data can cause deployment failures even when tests pass in the source org. This article provides a step-by-step process to clear test history, recompile all Apex classes, run all tests, and validate the estimated coverage using the ApexOrgWideCoverage object — all prior to deployment. It also explains how adding new Apex code affects the overall coverage calculation.
Code coverage indicates how many lines of Apex code are executed when tests run. Salesforce requires a minimum of 75% code coverage across the entire org for a deployment to succeed. The steps below help ensure your coverage data is accurate before attempting a deployment.
SELECT PercentCovered FROM ApexOrgWideCoveragePercentCovered field returns the organization-wide Apex code coverage percentage. This result should match the estimate from Step 4-5.@isTest(SeeAllData=true), which can introduce metadata dependencies that reduce coverage.@isTest(SeeAllData=true) behavior.
000386953

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.