June 3, 2014

SOQL to find code coverage in Salesforce

Code coverage is stored in two Lightning Platform Tooling API objects: 
1. ApexCodeCoverageAggregate:
ApexCodeCoverageAggregate stores the sum of covered lines for a class after checking all test methods that test it. 
 
2. ApexCodeCoverage:
ApexCodeCoverage stores the lines that are covered and uncovered by each individual test method.
 
 
1. Query:

SELECT ApexClassOrTrigger.Name, NumLinesCovered, NumLinesUncovered FROM ApexCodeCoverageAggregate ORDER BY ApexClassOrTrigger.Name ASC

Output: 

 
2. Query:
SELECT ApexClassOrTrigger.Name, NumLinesCovered, NumLinesUncovered FROM ApexCodeCoverage
 
Test class in Developer console always shows None issue - https://www.infallibletechie.com/2018/07/test-class-in-developer-console-always.html

3 comments:

  1. why is this not work in developer console?

    ReplyDelete
    Replies
    1. Enable "Use Tooling API" check box in Developer Console to execute this query.

      Delete