function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jorge Diaz 28Jorge Diaz 28 

Overall ORG Code Coverage is at 68%!?

Have any of you seen this happen before. How can my ORG be at 68%???? 
Suraj Tripathi 47Suraj Tripathi 47

Hi Jorge,

It shows the test classes coverage of your ORG.

Follow these steps every time you run the code coverage to have reliable coverage details:
Navigate to Setup

In the Quick Find Search type 'Apex' and select 'Apex Test Execution'
1. Click Options
2. Deslect 'Store Only Aggregated Code Coverage' and click 'OK'
3.Click 'View test history'
4.Click 'Clear all test history'


In the Quick Find Search type 'Apex' and click 'Apex Classes'
Click 'Compile all classes'
In the Quick Find Search type 'Apex' and select 'Apex Test Execution'
Click 'Run all tests'
 
 
After the completed run, check the overall code coverage for your org by navigating to:
In the Quick Find Search type 'Apex' and click 'Apex Classes'
Click 'Estimate your organization's code coverage'
 
If you still lack confidence in your coverage, please use the Tooling API to determine coverage. 
We can use Tooling API to calculate the coverage individually for an Apex class/Apex trigger or overall coverage. 


How many lines are covered for a specific class or trigger: 
SELECT NumLinesCovered, NumLinesUncovered FROM ApexCodeCoverage WHERE ApexClassOrTriggerId = '01XXXXXXXXXXXXX'
Which lines are covered for a specific class or trigger: 
SELECT Coverage FROM ApexCodeCoverage WHERE ApexClassOrTriggerId = '01XXXXXXXXXXXXX'
The current org-wide coverage: 
SELECT PercentCovered FROM ApexOrgWideCoverage 
To test these queries you may use Workbench (workbench.developerforce.com) as follows:
Navigate to Utilities | REST Explorer
Select GET
Enter the following URL: 
/services/data/v29.0/tooling/query/?q=YOUR_QUERY 
where YOUR_QUERY should be the query to execute
Click 'Show Raw Response' 

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

Please mark it as the best answer so that other people would take references from it.

Thanks

Suraj Tripathi 47Suraj Tripathi 47
To deploy into Production any Apex Code should have 75% code coverage but at the same time Salesforce allows us to deploy the Apex Code which is having above 1% by considering overall code coverage is above 75%.

But the best practice it to maintain the 75% code coverage for all the classes / triggers.

What I would suggest here is,

Take any of the 5 test classes and start working on it to increase the code coverage to 75%.

Remember any class / trigger above 1% code coverage you can able to deploy but that is not the best practice. 
Jorge Diaz 28Jorge Diaz 28
Im at your Tooling API step but i cannot find it.