Skip to content

Instantly share code, notes, and snippets.

@tyoshikawa1106
Created May 5, 2014 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyoshikawa1106/bb05a7c9da5cff5dd5fd to your computer and use it in GitHub Desktop.
Save tyoshikawa1106/bb05a7c9da5cff5dd5fd to your computer and use it in GitHub Desktop.
apex:RemoteObjects Sample
<apex:page >
<!-- Remote Objects definition to set accessible sObjects and fields -->
<apex:remoteObjects >
<apex:remoteObjectModel name="Account" jsShorthand="Warehouse" fields="Name,Id">
<apex:remoteObjectField name="Phone" jsShorthand="Phone"/>
</apex:remoteObjectModel>
</apex:remoteObjects>
<!-- JavaScript to make Remote Objects calls -->
<script>
fetchWarehouses = function(){
// Create a new Remote Object
var wh = new SObjectModel.Warehouse();
// Use the Remote Object to query for 10 warehouse records
wh.retrieve({
limit : 10,
where : {
Name {
eq : 'GenePoint'
}
}
}, function(err, records){
if(err) alert(err.message);
else {
var ul = document.getElementById("warehousesList");
records.forEach(function(record) {
// Build the text for a warehouse line item
var whText = record.get("Name");
whText += " -- ";
whText += record.get("Phone");
// Add the line item to the warehouses list
var li = document.createElement("li");
li.appendChild(document.createTextNode(whText));
ul.appendChild(li);
});
}
});
};
</script>
<h1>Retrieve Warehouses via Remote Objects</h1>
<p>Warehouses:</p>
<ul id="warehousesList">
</ul>
<button onclick="fetchWarehouses()">Retrieve Warehouses</button>
</apex:page>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment