Activity Forums Salesforce® Discussions How to get code coverage programmatically through Apex?

  • Abhinav

    Member
    August 11, 2016 at 4:11 pm

    Hi Tanu,

    For synchronous testing: The RunTestsResult returned by calling ApexService.runTests() contains a codeCoverage property, which is a CodeCoverageResult array.

    The CodeCoverageResult locationsNotCovered property gives you the line number and column of code that wasn't tested in the run.

    My experience with this is that it will return code coverage results for any class that gets touched by the test case(s) and you don't get any control over it. Also, it isn't a cumulative view of the code coverage, only what is covered by that specific test run. So you can get lots of results indicating very low code coverage for classes that weren't being targeted by the test cases in the run but might otherwise have really good coverage.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos