Remote Objects Tidbits

My last article, Hierarchies with Remote Objects and jsTree, came out of my desire to build something interesting using Remote Objects as a way to learn their features and an interest in learning how to use jsTree.  As I was developing the code in that article, I discovered a few more useful ways to interact with Remote Objects in JavaScript and have documented them below.

Function Query Criteria

The query criteria in a retrieve call can be an object or a function that returns one.  A use case for using a function is to build search criteria based on some sort of user input.  For example, the following code generates the selection criteria dynamically based on whether or not a “Begins With” search has been specified.


There is an offset clause that can be used in the retrieve function to enable paging of results.  This could be used to load in more records dynamically with something like an infinite scroll or button click.  A simple example is as follows.

Dynamic Method Calls

Since the Remote Object methods are properties on an object they can be invoked by accessing the property of the object using square bracket notation.  Here is an example that dynamically calls the create or update function of a model instance, depending on whether or not the “Id” field is set on the model.


The Visualforce Developer’s Guide has excellent documentation on Remote Objects.  If you are considering using Remote Objects in your application the Best Practices for Using Remote Objects section is an excellent reference.  Also, keep in mind that Remote Objects are in developer preview and not yet feature complete.

2 thoughts on “Remote Objects Tidbits

Leave a Reply

Your email address will not be published. Required fields are marked *