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.SObject
  • Force.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.

  1. In the <body> tag, create a <script> object.

  2. In the <script> tag, create a model object for the Salesforce user sObject. Extend Force.SObject, and specify the sObject type and the fields we are targeting.

  3. Immediately after setting the User object, create a UserCollection object to hold user search results. Extend Force.SObjectCollection, and specify your new model (app.models.User) as the model for items in the collection.

  4. In this collection, implement a function named setCriteria that 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.