The "Estimate your organization's code coverage" link in Salesforce Setup provides an estimate of your Apex code coverage but is not 100% precise. This article explains how to obtain a reliable, accurate code coverage calculation for your Salesforce org, using both the Apex Test Execution tool and the Tooling API.
Apex code coverage is a measure of how many lines of your Apex code are executed by your test classes. Salesforce requires at least 75% overall code coverage to deploy Apex to production.
Follow these steps each time you want to obtain an accurate code coverage result for your org:
After all tests complete, check your org's overall code coverage:
If you need more precise or programmatic coverage data, use the Salesforce Tooling API to query coverage at the individual class or trigger level, or for the entire org.
The Tooling API is a REST-based API that provides access to metadata and debugging information in Salesforce, including Apex code coverage data.
Query 1 — Number of lines covered for a specific Apex class or trigger: Query the ApexCodeCoverage object filtering by ApexClassOrTriggerId. Replace the ID with your 15 or 18-character Apex class or trigger ID. The result returns NumLinesCovered and NumLinesUncovered fields.
Query 2 — Which specific lines are covered for a class or trigger: Query the ApexCodeCoverage object for the Coverage field, filtering by ApexClassOrTriggerId. Replace the ID with your actual class or trigger ID.
Query 3 — Current org-wide code coverage percentage: Query the ApexOrgWideCoverage object and retrieve the PercentCovered field. This returns the overall code coverage percentage for your entire Salesforce org.
Running these queries in Workbench: You can test these Tooling API queries using Workbench (workbench.developerforce.com). Navigate to Utilities, then REST Explorer. Select GET, enter the URL /services/data/v29.0/tooling/query/?q=YOUR_QUERY replacing YOUR_QUERY with the SOQL statement, and click Show Raw Response.
If you still have concerns about your coverage, perform a production validation by clicking the Validate Only button in your deployment tool. The tool displays errors or warnings if any classes have insufficient coverage.
000386327

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.