Thursday, 8 December 2016

SQOL to know Code coverage in Salesforce


Salesforce provides developers a way to find out Codecoverage details. 
Write a SQOL by using  “ApexCodeCoverageAggregate”  to know Code coverage for all Apex Classes and Apex Triggers withing fraction of seconds. 

* SOQL :

SELECT ApexClassOrTrigger.Name, NumLinesCovered, NumLinesUncovered FROM ApexCodeCoverageAggregate


Tips : 

* Use of "ORDER BY" clause will let you have your result more presentable.

e.g. 

SELECT ApexClassOrTrigger.Name, NumLinesCovered, NumLinesUncovered FROM ApexCodeCoverageAggregate ORDER BY  ApexClassOrTrigger.Name ASC




* Make sure that you have enabled "Use Tooling API" check box in Developer Console to execute following query.  (see following image - Red circle)