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


8 comments:

  1. We as QuickBooks Support Phone Number +1-844-233-5335 team provide our matchless support for the issues in QuickBooks to its users worldwide. It goes without saying that QuickBooks is one of the most helpful accounting software presents in the current time. Read more- https://tinyurl.com/yy9ov86q & visit us- https://www.qbooksupportphonenumber.com/

    ReplyDelete
  2. QuickBooks has completely transformed the way people used to run their business earlier. In order to get used to it, one should welcome this positive change. Supervisors at QuickBooks Support Phone Number 800-417-3165 have trained all their executives to combat the issues in this software. Read more- https://tinyurl.com/y52oohj6 & visit us- https://www.qbcustomersupportphonenumber.com/

    ReplyDelete
  3. QuickBooks is one of the most widely used accounting software, it also offers you a range of versions. We provide help at QuickBooks Payroll Support Phone Number +1-844-233-5335 to deal with the issues in this QuickBooks version. Read more- https://tinyurl.com/y4rwdn9t & visit us- https://www.qbooksupportphonenumber.com/quickbooks-payroll/

    ReplyDelete
  4. Our support team at QuickBooks Payroll Support Phone Number +1-800-417-3165 helps you deal with the issues that pop up in this software. When it comes to errors, there are so much that you may face. Read more- https://tinyurl.com/y6crto3c & visit us- https://www.qbcustomersupportphonenumber.com/quickbooks-payroll/

    ReplyDelete
  5. 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
  6. Quickbooks Support Phone Number offers help to third-party services like QuickBooks Enterprise support and QuickBooks support and products such as, Plus, Premium, Pro, which is additionally accessible on the QuickBooks website.
    Quickbooks Support Phone Number

    ReplyDelete
  7. 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
  8. Very Nice Post! Thank you so much for sharing this informative post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
    Saleforce Developer Training in Electronic City

    ReplyDelete