+ Start a Discussion

how to query code coverage in apex using soql queries??????

is it possible to query codecoverage in apex using soql quries.????????
Cory CowgillCory Cowgill
No, you cannot pull the code coverage via a SOQL Query.

If you need to access the metadata layer of the platform you can use the Force.com Metadata API - http://www.salesforce.com/us/developer/docs/api_meta/.

With the metadata api you can do things like query the objects, execute unit tests, etc.

I don't know if you can query with SOQL, but you can use SOAP or Rest to get the information.  Check out the Tooling API dev guide:

It gives this SOQL example:

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

but I could make this work in Dev Console, so I don't know if it will work in other Apex code.


Should read "but I COULDN'T make this work..."
Unfortunately this is not possible through the SOAP API

Satish Kumar
Jyothieswar ReddyJyothieswar Reddy
You can do it.

1) Go to www.aside.io
2) Login with your Sandbox/Production credentials and allow requirements
3) Click "data" on top right (just above your username).
4) Write SOQL Query over there (For ex : SELECT ApexClassOrTrigger.Name, NumLinesCovered, NumLinesUncovered FROM ApexCodeCoverageAggregate ORDER BY ApexClassOrTrigger.Name ASC) and click "query" button on left top tabs.
5) You will find the results, and the results can be exported by clicking "export" button on left top tabs.

Let me know if you have any questions.

Ashu sharma 38Ashu sharma 38

We can write test code for SOQL???