Created
February 17, 2015 16:50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page > | |
<!-- Remote Objects definition to set accessible sObjects and fields --> | |
<apex:remoteObjects > | |
<apex:remoteObjectModel name="Account" jsShorthand="Acc" fields="Name,Id"> | |
<apex:remoteObjectField name="Industry" jsShorthand="Indust"/> | |
</apex:remoteObjectModel> | |
</apex:remoteObjects> | |
<!-- JavaScript to make Remote Objects calls --> | |
<script> | |
var fetchAccounts = function(){ | |
// Create a new Remote Object | |
var wh = new SObjectModel.Account(); | |
// Use the Remote Object to query for 10 Account records | |
wh.retrieve({ limit: 10 }, function(err, records, event){ | |
if(err) { | |
alert(err.message); | |
} | |
else { | |
var ul = document.getElementById("AccountList"); | |
records.forEach(function(record) { | |
var whText = record.get("Name"); // Build the text for a Position line item | |
whText += " -- "; | |
whText += record.get("Indust"); | |
// Add the line item to the Positions list | |
var li = document.createElement("li"); | |
li.appendChild(document.createTextNode(whText)); | |
ul.appendChild(li); | |
}); | |
} | |
}); | |
}; | |
</script> | |
<h1>Retrieve Accounts via Remote Objects</h1> | |
<p>Accounts:</p> | |
<ul id="AccountList"> </ul> | |
<button onclick="fetchAccounts ()">Retrieve Accounts</button> | |
</apex:page> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment