Skip to content

Instantly share code, notes, and snippets.

@gitmatheus
Last active September 17, 2018 22:46
Show Gist options
  • Save gitmatheus/cfa4066d666e6000a40c5b5ff88cc73b to your computer and use it in GitHub Desktop.
Save gitmatheus/cfa4066d666e6000a40c5b5ff88cc73b to your computer and use it in GitHub Desktop.
String baseURL = 'https://' + System.URL.getSalesforceBaseUrl().getHost();
string queryStr = 'SELECT+NumLinesCovered,ApexClassOrTriggerId,ApexClassOrTrigger.Name,NumLinesUncovered,Coverage+FROM+ApexCodeCoverageAggregate';
String ENDPOINT = baseURL + '/services/data/v40.0/tooling/';
HttpRequest req = new HttpRequest();
req.setEndpoint(ENDPOINT + 'query/?q=' + queryStr);
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());
req.setHeader('Content-Type', 'application/json');
req.setMethod('GET');
req.setTimeout(80000);
Http http = new Http();
HTTPResponse res = http.send(req);
System.debug(res.getBody());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment