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.
Models
Models on the client represent server records. In Mobile Sync, model objects are instances of Force.SObject, a subclass of the Backbone.Model class. SObject extends Model to work with Salesforce APIs and, optionally, with SmartStore.
You can perform the following CRUD operations on SObject model objects:
- Create
- Destroy
- Fetch
- Save
- Get/set attributes
In addition, model objects are observable: Views and controllers can receive notifications when the objects change.
Properties
- sobjectType
- Required. The name of the Salesforce object that this model represents. This value can refer to either a standard object or a custom object.
- fieldlist
- Required. Names of fields to fetch, save, or destroy.
- cacheMode
- Offline behavior.
- mergeMode
- Conflict handling behavior.
- cache
- For updatable offline storage of records. The Mobile Sync comes bundled with Force.StoreCache, a cache implementation that is backed by SmartStore.
- cacheForOriginals
- Contains original copies of records fetched from server to support conflict detection.
Examples
- As properties on a Force.SObject instance.
- As methods on a Force.SObject sub-class. These methods take a parameter that specifies the desired CRUD action (“create”, “read”, “update”, or “delete”).
- In the options parameter of the fetch(), save(), or destroy() function call.
1// As properties on a Force.SObject instance
2acc = new Force.SObject({Id:"<some_id>"});
3acc.sobjectType = "account";
4acc.fieldlist = ["Id", "Name"];
5acc.fetch();1// As methods on a Force.SObject sub-class
2Account = Force.SObject.extend({
3 sobjectType: "account",
4 fieldlist: function(method) { return ["Id", "Name"];}
5});
6Acc = new Account({Id:"<some_id>"});
7acc.fetch();1// In the options parameter of fetch()
2acc = new Force.SObject({Id:"<some_id>"});
3acc.sobjectType = "account";
4acc.fetch({fieldlist:["Id", "Name"]);