3

I ran a query in REST Explorer ( on ApexCodeCoverage ). Im getting duplicate (and wrong) results. Few classes/triggeres are repeated with different results.

A class ApplicationInfoHelper is being repeated many times in the results, with different lines (un)covered results. Same with many other classes in these results.

Atleast the lines covered/uncovered should be same, even if the class is repeating. [Note the Ids are the same, so I'm sure it is the same class]

3 Answers 3

5

ApexCodeCoverage has a row per test method. If you were to add TestMethodName to your SOQL query you would see the test case that is responsible for the NumLinesCovered.

NumLinesCovered and NumLinesUncovered vary as each test method touches different lines.

You can drill further down to Coverage to see specifically which lines were hit and which weren't.


Instead you might want to use the SOQL queries that the developer console does:

ApexCodeCoverageAggregate - Represents aggregate code coverage test results for an Apex class or trigger.

SELECT ApexClassOrTriggerId, ApexClassOrTrigger.Name, NumLinesCovered, NumLinesUncovered FROM ApexCodeCoverageAggregate WHERE ApexClassOrTriggerId != NULL AND ApexClassOrTrigger.Name != NULL AND (NumLinesCovered > 0 OR NumLinesUncovered > 0) AND NumLinesCovered != NULL AND NumLinesUncovered != NULL ORDER BY ApexClassOrTrigger.Name

ApexOrgWideCoverage - Represents code coverage test results for an entire organization.

SELECT PercentCovered FROM ApexOrgWideCoverage

Note: both of these SOQL queries are against the tooling API.

12
  • Its not SOQL I guess. I get the error " sObject type 'ApexOrgWideCoverage' is not supported" I will try in REST Explorer Commented Jan 21, 2015 at 10:00
  • @BruceLee It is SOQL, I've successfully executed both queries against the tooling API. Commented Jan 21, 2015 at 18:21
  • How can I run this query in the workbench?
    – abhi
    Commented Feb 17, 2016 at 20:08
  • 1
    @abhi I don't think you can directly run a SOQL query against the Tooling API in the Workbench SOQL Query tool. Instead you could use the REST Explorer under utilities. The Developer Console and the Fuse IT SFDC Explorer both support SOQL against the Tooling API. Commented Feb 17, 2016 at 23:19
  • 1
    @DanielBallinger I haven't raised a case. Wasn't sure if this was intended functionality or not, but just wanted to state that clearly for anyone who might read this Commented Mar 5, 2020 at 21:48
0

I think you are seeing this result because different tests are covering different parts of the class. If you either specific a specific testclass ID, or a specific Class ID, you should get the consolidated value.

0

This can be accomplished with the Salesforce Inspector Chrome Extension

  1. Install the Salesforce Inspector Chrome Extension
  2. From an SFDC window, click on the caret on the right side of screen to open the inspector
  3. Put the query in the query editor (sorry, still can't get the name of the class), and make sure use tooling api is selected

    SELECT ApexClassOrTriggerId,  NumLinesCovered, NumLinesUncovered
    FROM ApexCodeCoverageAggregate
    WHERE ApexClassOrTriggerId != NULL
    AND ApexClassOrTrigger.Name != NULL
    AND (NumLinesCovered > 0 OR NumLinesUncovered > 0)
    AND NumLinesCovered != NULL
    AND NumLinesUncovered != NULL
    ORDER BY ApexClassOrTrigger.Name
    
  4. Click export and choose your format.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .