I want to find ApexClass code coverage before deployment. Is there any way to get the code coverage using tooling API.

  • 3
    Have you done any research at all? Why do you not just check in the Developer Console or through the UI? There are a lot of ways to check current coverage... – Adrian Larson Apr 17 '17 at 14:43

This will help you get started in the right direction.

Checking Code Coverage

Reliable ways to calculate Overall Code Coverage in salesforce

SOQL to find code coverage in Salesforce

| improve this answer | |
  • Thanks for the reply. My scenario is I want the code coverage of an apex class before deployment to the target environment. For ex. If I use ApexCodeCoverage or ApexCodeCoverageAggregate and test in dev environment, I get the code coverage of a particular class but if I deploy that class to target environment the code coverage of that class might be different so is there any option in tooling API to validate the CodeCoverage in both the Environment.(Ex. CheckOnly ) – amit patil Apr 18 '17 at 5:41

The Tooling API gives you three resources for monitoring code coverage:

  1. ApexCodeCoverage

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

  2. ApexCodeCoverageAggregate

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

  3. ApexOrgWideCoverage

    Represents code coverage test results for an entire organization.

You will likely want ApexCodeCoverageAggregate filtered by the ApexClassorTriggerId. It will give you the high level NumLinesCovered and NumLinesUncovered plus the detailed Coverage field.

| 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.