You need to sign in to do that
Don't have an account?
Query on ApexCodeCoverageAggregate.
Hi All,
I have to query on ApexCodeCoverageAggregate. I tried like this, but not able to get the result, is there any one have sample codes on this can you please post it. I need how use these Tooling API Objects. Please post with sample class and procedure how to execute these.
I tried like below.
public class SampleClass
{
public List<ApexCodeCoverageAggregate> getCoverage()
{
List<ApexCodeCoverageAggregate> apexCodeCoverageList = [SELECT NumLinesCovered, NumLinesUncovered, ApexClassorTriggerId FROM ApexCodeCoverageAggregate];
System.debug('@@@:apexCodeCoverageList: '+apexCodeCoverageList);
return apexCodeCoverageList;
}
This code is not working.
Thanks
Venkat
I have to query on ApexCodeCoverageAggregate. I tried like this, but not able to get the result, is there any one have sample codes on this can you please post it. I need how use these Tooling API Objects. Please post with sample class and procedure how to execute these.
I tried like below.
public class SampleClass
{
public List<ApexCodeCoverageAggregate> getCoverage()
{
List<ApexCodeCoverageAggregate> apexCodeCoverageList = [SELECT NumLinesCovered, NumLinesUncovered, ApexClassorTriggerId FROM ApexCodeCoverageAggregate];
System.debug('@@@:apexCodeCoverageList: '+apexCodeCoverageList);
return apexCodeCoverageList;
}
This code is not working.
Thanks
Venkat
a) ApexCodeCoverage contains coverage per class per test class
b) ApexCodeCoverageAggregate contains coverage per class for all test classes
c) ApexOrgWideCoverage contains coverage overall for all classes in the org
available from Tooling API.. These are not the regular Sobjects to get the data via SOQL using APEX...
So you need to send an request to Tooling API to get the information what ever you want from APEX. Below is the sample code that I used to get the custom object ID via Tooling API. Hope it makes sense.
All Answers
a) ApexCodeCoverage contains coverage per class per test class
b) ApexCodeCoverageAggregate contains coverage per class for all test classes
c) ApexOrgWideCoverage contains coverage overall for all classes in the org
available from Tooling API.. These are not the regular Sobjects to get the data via SOQL using APEX...
So you need to send an request to Tooling API to get the information what ever you want from APEX. Below is the sample code that I used to get the custom object ID via Tooling API. Hope it makes sense.
Thanks!
I have modified code like this. I am getting system callout exception on RemoteSite Settings. Can you please send me full steps and I have to send email thse class names and code coverage. Can I store the reuslt in list.
String objectIdQuery = 'SELECT ApexClassorTriggerId, NumLinesCovered, NumLinesUncovered FROM ApexCodeCoverageAggregate';
String environmentURL = URL.getSalesforceBaseUrl().toExternalForm() + '/services/data/v28.0/tooling/query/?q=' + EncodingUtil.urlEncode(objectIdQuery, 'UTF-8');
HttpRequest req = new HttpRequest();
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());
req.setHeader('Content-Type', 'application/json');
req.setEndpoint(environmentURL);
req.setMethod('GET');
Http h = new Http();
return h.send(req).getBody();
Thanks & Regards
Venkat
I am calling this method in @future(Callout=true), UserInfo.getSessionID() getting null. Can you please post for this any alternate.
Thanks
Venkat
I am Calling future method from schedule apex, getting an error: System.HttpResponse[Status=Unauthorized, StatusCode=401]
I think we are getting because of UserInfo.getSessionId() null, If I comment hilighted line also I am getting same error. Is there any solution for this. or Can I schedule the callouts?
public class Sample
{
@future(Callout = true)
public static void getCoverageforClasses()
{
String objectIdQuery = 'SELECT ApexClassorTriggerId, NumLinesCovered, NumLinesUncovered FROM ApexCodeCoverageAggregate';
String environmentURL = URL.getSalesforceBaseUrl().toExternalForm() + '/services/data/v28.0/tooling/query/?q=' + EncodingUtil.urlEncode(objectIdQuery, 'UTF-8');
HttpRequest req = new HttpRequest();
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());
req.setHeader('Content-Type', 'application/json');
req.setEndpoint(environmentURL);
req.setMethod('GET');
Http h = new Http();
return h.send(req).getBody();
}
}
Thanks
Venkat