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

Force.SObject adds the following properties to Backbone.Model:
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

You can assign values for model properties in several ways:
  • 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.
For example, these code snippets are equivalent.
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"]);