Friday, April 19, 2019

Way to export Code Coverage of Individual ApexClass or Trigger in .csv format

Salesforce provide Tooling API (REST API) through which we can find org metadata information.  Tooling API provide object called "ApexCodeCoverage" which can be used to find code coverage information about individual class or trigger or Org complete code coverage information.

I have created a apex script which can be run in developer console in "Execute Anonymous Window". After running this script, you will receive an email with .csv file which will contain information about code coverage for each apex class or trigger.

Below is snapshot of .csv file which you will recieve:


By using Tooling API you can find overall code coverage of your organization. Below is script which you can use in "Execute Anonymous Window".

Important things to consider in order to get have reliable coverage details:

  • Go to setup --> apex test execution ---> click on Options ---> deselect the Store only aggregate code coverage option.
  • Go to Setup --> Apex test execution ----> Clear all test history.
  • Go to Setup --> Apex classes ---> Compile all classes.
  • Go to Setup ---> Apex test execution ---> Run all test.
Once Run All Test is completed, then above scripts to get actual code coverage details of all classes or trigger or to get overall Org code coverage percentage.

You can also run the queries on "apexCodeCoverage" and "ApexOrgWideCoverage" object in developer console query editor by selecting tooloing api checkbox.

To get Org Overall Code coverage use below Query:

"SELECT PercentCovered FROM ApexOrgWideCoverage "



To get code coverage of specific apex class or trigger use below query:

SELECT Coverage FROM ApexCodeCoverage WHERE ApexClassOrTriggerId = 'xxxxxxxxx'
where xxxxxxxxx = 15 or 18 digit apex class or apex trigger id.



Hope this will help!!

Looking forward for everyone comments and suggestions...


5 comments:

  1. In such a situation, we recommend that you dial the toll-free QuickBooks Payroll Technical Support Number and get help from the one of the finest QuickBooks ProAdvisors of the country.

    Quickbooks Payroll Support Phone Number

    ReplyDelete
  2. Nice Blog Thanks for sharing this useful link. It’s a really informative for all. QuickBooks is one of the best accounting software which helps in managing your company finances and accounting. Any technical issue obstructing your way ahead? Call us now on Quickbooks for MAC support phone number 1-800-986-4607.

    ReplyDelete
  3. I was reading some of your content on this website and I conceive this internet site is really informative ! Keep on putting up. z code system discount

    ReplyDelete
  4. This is like a mobile phone in the age of postcards😄

    ReplyDelete