- <apex:page >
- <script type="text/javascript">
- var __sfdcSessionId = '{!GETSESSIONID()}';
- </script>
- <script src="../../soap/ajax/29.0/connection.js" type="text/javascript"/>
- <script>
- window.onload = setupPage;
- function setupPage() {
- var output = document.getElementById("output");
- var startTime = new Date().getTime()
- try {
- var queryResult = sforce.connection.query("Select Id, Name, Industry From Account order by Industry limit 30");
- layoutResults(queryResult, output, startTime);
- } catch(error) {
- queryFailed(error, output);
- }
- }
- function queryFailed(error, out) {
- out.innerHTML = "<font color=red>An error has occurred:</font> <p>" + error;
- }
- function layoutResults(queryResult, out, startTime) {
- var timeTaken = new Date().getTime() - startTime;
- if (queryResult.size > 0) {
- var output = "";
- var records = queryResult.getArray('records');
- for (var i = 0; i < records.length; i++) {
- var account = records[i];
- output += account.Id + " " + account.Name + " [Industry - "+ account.Industry + "]<BR>";
- }
- out.innerHTML = output + "<BR> query completed in: " + timeTaken + " ms.";
- } else {
- out.innerHTML = "No records matched.";
- }
- }
- </script>
- <div id="output"></div>
- </apex:page>
Quick Link to parent document: Embedding API Calls in JavaScript
No comments:
Post a Comment
Thank you for visiting. Your comments are highly appreciated.