Skip to content

Instantly share code, notes, and snippets.

@metadaddy
Created June 25, 2013 17:18
Show Gist options
  • Save metadaddy/5860374 to your computer and use it in GitHub Desktop.
Save metadaddy/5860374 to your computer and use it in GitHub Desktop.
Visualforce page to run arbitrary queries on the Force.com REST APIs. See http://blogs.developerforce.com/developer-relations/2013/06/calling-the-force-com-rest-api-from-visualforce-pages-revisited.html for more details.
<apex:page >
<apex:includeScript value="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"/>
<script>
jQuery(document).ready(function($) {
$('#queryform').submit(function(){
$.ajax($('#query').val(),
{
beforeSend: function(xhr) {
xhr.setRequestHeader('Authorization', 'Bearer {!$Api.Session_ID}');
},
success: function(response) {
$('#results').text(JSON.stringify(response, null, ' '));
},
error: function(jqXHR, textStatus, errorThrown) {
alert(jqXHR.status + ': ' + errorThrown);
}
});
return false;
});
});
</script>
<h1>Test REST API from JavaScript</h1>
<form id="queryform">
<input id="query" size="120" value="/services/data/v28.0/query?q=SELECT+Name+FROM+Account+LIMIT+10"/>
<input type="submit" id="submit" value="Submit" />
</form>
<p>Results:</p>
<pre id="results">
</pre>
</apex:page>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment