Print this page

Reliable ways to calculate Overall Code Coverage in salesforce

Knowledge Article Number 000199478
In Winter 14, we changed the link name from "Calculate your organization's code coverage" to "Estimate your organization's code coverage". As the name suggests, it's an estimate and not the true number.
Below are few steps to check the reliability of the "Estimate your organization's code coverage" option.

Please follow the below steps every time you run the code coverage and you will have reliable coverage details. 

Go to setup --> apex test execution ---> click on Options ---> uncheck the Store only aggregate code coverage option. 

Go to Setup --> Apex test execution ----> View test history and Clear all test history 

Go to Setup --> Apex classes ---> Compile all classes 

Go to Setup ---> Apex test execution ---> Run all test 

After the run is completed, check the overall code coverage for your ORG by navigating to 

Setup --> Apex classes -->Calculate Overall Code Coverage (or) on the Developer Console 

If you are still not confident enough, you can use tooling API to determine the coverage. 

We can use Tooling API  to calculate the coverage individually for an apex class/ apex trigger or overall coverage. 

1) How many lines are covered for a specific class or trigger: 

SELECT NumLinesCovered, NumLinesUncovered FROM ApexCodeCoverage WHERE ApexClassOrTriggerId = 

2) Which lines are covered for a specific class or trigger: 

SELECT Coverage FROM ApexCodeCoverage WHERE ApexClassOrTriggerId = 

3) The current org-wide coverage: 

SELECT PercentCovered FROM ApexOrgWideCoverage 

To test these queries you may use Workbench ( as follows: 1) Go to Utilities | REST Explorer 2) Select GET 3) Enter the following URL: 


where YOUR_QUERY should be the query to execute

4) Click "Show Raw Response". 

If you are still not confident enough, then you can do a production validation (click on validate only button in the tool which you are using to deploy) and it will give you errors/warnings if there is no coverage for classes. 

promote demote