Created
May 5, 2014 13:43
-
-
Save tyoshikawa1106/bb05a7c9da5cff5dd5fd to your computer and use it in GitHub Desktop.
apex:RemoteObjects Sample
This file contains 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="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