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.
Force.SObject adds the following properties to Backbone.Model:
sobjectTypeRequired. The name of the Salesforce object that this model represents. This value can refer to either a standard object or a custom object.
fieldlistRequired. Names of fields to fetch, save, or destroy.
cacheModemergeModecacheFor updatable offline storage of records. The Mobile Sync comes bundled with Force.StoreCache, a cache implementation that is backed by SmartStore.
cacheForOriginalsContains original copies of records fetched from server to support conflict detection.
You can assign values for model properties in several ways:
- As properties on a
Force.SObjectinstance. - As methods on a
Force.SObjectsub-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(), ordestroy()function call.
For example, these code snippets are equivalent.