Create a Mobile Sync Model and a Collection
Now that we’ve configured the HTML infrastructure, let’s get started using Mobile Sync by extending two of its primary objects:
Force.SObjectForce.SObjectCollection
These objects extend Backbone.Model, so they support the Backbone.Model.extend() function. To extend an object using this function, pass it a JavaScript object containing your custom properties and functions.
-
In the
<body>tag, create a<script>object. -
In the
<script>tag, create a model object for the Salesforce user sObject. ExtendForce.SObject, and specify the sObject type and the fields we are targeting. -
Immediately after setting the User object, create a
UserCollectionobject to hold user search results. ExtendForce.SObjectCollection, and specify your new model (app.models.User) as the model for items in the collection. -
In this collection, implement a function named
setCriteriathat takes a search key and builds a SOQL query using it. You also need a getter to return the key at a later point.
Here’s the complete model code.