Skip to content

Instantly share code, notes, and snippets.

@karanrajs
Created February 26, 2015 18:01
Show Gist options
  • Save karanrajs/257a9dad2db6262298fa to your computer and use it in GitHub Desktop.
Save karanrajs/257a9dad2db6262298fa to your computer and use it in GitHub Desktop.
Visualforce page to get the overall code coverage of org using Tooling API
<apex:page showHeader="true" sidebar="true" docType="html-5.0" standardStylesheets="false">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
//Tooling API query to get the overall code coverage
$.ajax('/services/data/v30.0/tooling/query/?q=SELECT PercentCovered FROM ApexOrgWideCoverage',
{
beforeSend: function(xhr) {
xhr.setRequestHeader('Authorization', 'Bearer {!$Api.Session_ID}');
},
success: function(response) {
//if the response is success, then it will return the result
$.each(response.records, function(index, record) {
//appending the result in a page
$('#percen').append(record.PercentCovered);
});
},
error: function(jqXHR, textStatus, errorThrown) {
alert(jqXHR.status + ': ' + errorThrown);
}
}
);
});
</script>
<p id="percen">Over all code coverage: </p>
</apex:page>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment