-3

Is there any way we can query Like below and get the result

Query: SELECT Percentagecovered,ApexClassname FROM ApexCodeCoverage or How can i convert below query to get % covered.

SELECT ApexClassOrTrigger.Name, NumLinesCovered, NumLinesUncovered FROM ApexCodeCoverageAggregate ORDER BY ApexClassOrTrigger.Name ASC
1
  • What exactly are you asking about this Tooling API query? You have the lines covered and uncovered in your query already; you can calculate the percentage covered.
    – David Reed
    Aug 21 '18 at 3:04
1

To query for code coverage, specify an Apex class, test class, or both. The returned JSON or XML object will contain two lists of integers: one for covered and one for uncovered lines.

 SELECT Coverage FROM ApexCodeCoverage WHERE ApexClassOrTrigger = ‘01pD000000066GR’ AND ApexTestClass = ‘01pD000000064pu’ 

Coverage includes the following fields:

  • coveredLines
  • namespace
  • uncoveredLines

Code coverage percentage is a simple calculation of the number of covered lines divided by the sum of the number of covered lines and the number of uncovered lines. For example, to calculate code coverage percentage in SOAP:

ApexCodeCoverage acc = null; //Query for an ApexCodeCoverage object 
Coverage coverage = acc.coverage; 
int[] covered = coverage.coveredLines; 
int[] uncovered = coverage.uncoveredLines; 
int percent = covered.length / (covered.length + uncovered.length); 
System.out.println("Total class coverage is " + percent + "%.");

Reference:- ApexCodeCoverage

Better to go for other tool where you can easily get whole analysis:-

  1. https://www.aside.io/ //just login with your org and run all test get the whole analysis
  2. Salesforce advanced Code searcher:- By using the advanced quick find you can get your code few clicks shorter. Also, you can search any string your code
1
  • @DavidMycka Welcome :) Aug 21 '18 at 3:23

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.