Tooling API
Fetching the list of Classes along with their code coverage using Tooling API
Fetching the list of Classes along with their code coverage using Tooling API
We can find the list of classes along with their code coverages from external system.
PFB code to fetch the list of classes along with their coverage details, Using Tooling API.
(Here rest call is made, same can be implemented by SOAP).
----------------------------------------------------------------------------------------------------------------------
HTTPRequest req = new HTTPRequest();
String myQuery=’ select+id,ApexClassOrTrigger.Name,NumLinesCovered,NumLinesUncovered+from+ApexCodeCoverageAggregate’;
req.setEndpoint('<Login Instance> /services/data/v39.0/tooling/query/?q= '+myQuery); // Login Instance Example: https://demo727-dev-ed.my.salesforce.com
req.setMethod('GET');
req.setHeader('Authorization', 'Bearer ' +<Enter the Session Id>); // Example:UserInfo.getSessionId()
Http h = new Http();
HttpResponse res = h.send(req);
system.debug('Res '+res.getBody()); // Contains Jsonà parse it and find the list of the classes along with their test coverage.
----------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
OUTPUT:
----------------------------------------------------------------------------------------------------------------------
Note: you might asked to add the remote site setting.
Awesome
ReplyDeleteThis comment has been removed by the author.
ReplyDeletecan u provide me complete apex class code
ReplyDelete