Skip to content

Instantly share code, notes, and snippets.

@Sunil02kumar
Created February 17, 2015 16:50
Show Gist options
  • Save Sunil02kumar/187c38d5c121bf432135 to your computer and use it in GitHub Desktop.
Save Sunil02kumar/187c38d5c121bf432135 to your computer and use it in GitHub Desktop.
<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