Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
Force.RemoteObject Class
To support arbitrary REST calls, Mobile Sync introduces the Force.RemoteObject abstract class. Force.RemoteObject serves as a layer of abstraction between Force.SObject and Backbone.Model. Instead of directly subclassing Backbone.Model, Force.SObject now subclasses Force.RemoteObject, which in turn subclasses Backbone.Model. Force.RemoteObject does everything Force.SObject formerly did except communicate with the server.
Calling Custom Endpoints with syncRemoteObjectWithServer()
The RemoteObject.syncRemoteObjectWithServer() prototype method handles server interactions. Force.SObject implements syncRemoteObjectWithServer() to use the Salesforce Platform REST API. If you want to use other server end points, create a subclass of Force.RemoteObject and implement syncRemoteObjectWithServer(). This method is called when you call fetch() on an object of your subclass, if the object is currently configured to fetch from the server.
Example
The FileExplorer sample application is a Mobile Sync app that shows how to use Force.RemoteObject. HybridFileExplorer calls the Connect REST API to manipulate files. It defines an app.models.File object that extends Force.RemoteObject. In its implementation of syncRemoteObjectWithServer(), app.models.File calls Force.forceJsClient.fileDetails(), which wraps the /chatter/files/fileId REST API.
1app.models.File = Force.RemoteObject.extend({
2 syncRemoteObjectWithServer: function(method, id) {
3 if (method != "read")
4 throw "Method not supported " + method;
5 return Force.forceJsClient.fileDetails(id, null);
6 }
7})