2

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]

4

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.

| improve this answer | |
  • Its not SOQL I guess. I get the error " sObject type 'ApexOrgWideCoverage' is not supported" I will try in REST Explorer – sfdcFanBoy Jan 21 '15 at 10:00
  • @BruceLee It is SOQL, I've successfully executed both queries against the tooling API. – Daniel Ballinger Jan 21 '15 at 18:21
  • How can I run this query in the workbench? – abhi Feb 17 '16 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. – Daniel Ballinger Feb 17 '16 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 – James Quinn Mar 5 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.

| improve this answer | |
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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.