• john_m
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi,

I need a few pointers as to how to recursively fetch more than the 2000 record limit imposed by the REST API. I understand how one might do this using purely forcetk (with nextRecordsUrl and the 'done' attribute of the response) but how would I code this using the Backbone extensions?

I've included example code below. Everything works apart from being able to re-query Salesforce (using REST API) to retrieve the additional records.

My stack = Mobile SDK 2.1, Smartsync, Smartstore, Backbone, JQM, RequireJS

// The Contact Model
var Contact = Force.SObject.extend({
    sobjectType: "Contact",
    fieldlist: ["Id", "Name"],
    cache: function() { return App.caches.Contacts;},
    cacheMode: function(method) {
        if (!App.models.offlineTracker.get("isOnline")) {
            return Force.CACHE_MODE.CACHE_ONLY;
        }
        else {
            return (method == "read" ? Force.CACHE_MODE.CACHE_FIRST : Force.CACHE_MODE.SERVER_FIRST);
        }
    }   
});

// The Contact Collection
var ContactCollection = Force.SObjectCollection.extend({
    model: Contact,
    fieldlist: ["Id", "Name"],
    cache: function() { return App.caches.Contacts;}, 
});

// Fetch the records - assume over 2000 contact records
contacts = new ContactCollection();
contacts.config = {type:"soql", query:"SELECT Id, Name FROM Contact"};
contacts.fetch({
    success: function (data) {
     if (data.hasMore()) {
      // how can I use data.getMore()? I get 'RangeError: Maximum call stack size exceeded'
     }                    
    }                   
});

Many Thanks
  • January 21, 2014
  • Like
  • 1
Hi,

I need a few pointers as to how to recursively fetch more than the 2000 record limit imposed by the REST API. I understand how one might do this using purely forcetk (with nextRecordsUrl and the 'done' attribute of the response) but how would I code this using the Backbone extensions?

I've included example code below. Everything works apart from being able to re-query Salesforce (using REST API) to retrieve the additional records.

My stack = Mobile SDK 2.1, Smartsync, Smartstore, Backbone, JQM, RequireJS

// The Contact Model
var Contact = Force.SObject.extend({
    sobjectType: "Contact",
    fieldlist: ["Id", "Name"],
    cache: function() { return App.caches.Contacts;},
    cacheMode: function(method) {
        if (!App.models.offlineTracker.get("isOnline")) {
            return Force.CACHE_MODE.CACHE_ONLY;
        }
        else {
            return (method == "read" ? Force.CACHE_MODE.CACHE_FIRST : Force.CACHE_MODE.SERVER_FIRST);
        }
    }   
});

// The Contact Collection
var ContactCollection = Force.SObjectCollection.extend({
    model: Contact,
    fieldlist: ["Id", "Name"],
    cache: function() { return App.caches.Contacts;}, 
});

// Fetch the records - assume over 2000 contact records
contacts = new ContactCollection();
contacts.config = {type:"soql", query:"SELECT Id, Name FROM Contact"};
contacts.fetch({
    success: function (data) {
     if (data.hasMore()) {
      // how can I use data.getMore()? I get 'RangeError: Maximum call stack size exceeded'
     }                    
    }                   
});

Many Thanks
  • January 21, 2014
  • Like
  • 1
Hi,

I need a few pointers as to how to recursively fetch more than the 2000 record limit imposed by the REST API. I understand how one might do this using purely forcetk (with nextRecordsUrl and the 'done' attribute of the response) but how would I code this using the Backbone extensions?

I've included example code below. Everything works apart from being able to re-query Salesforce (using REST API) to retrieve the additional records.

My stack = Mobile SDK 2.1, Smartsync, Smartstore, Backbone, JQM, RequireJS

// The Contact Model
var Contact = Force.SObject.extend({
    sobjectType: "Contact",
    fieldlist: ["Id", "Name"],
    cache: function() { return App.caches.Contacts;},
    cacheMode: function(method) {
        if (!App.models.offlineTracker.get("isOnline")) {
            return Force.CACHE_MODE.CACHE_ONLY;
        }
        else {
            return (method == "read" ? Force.CACHE_MODE.CACHE_FIRST : Force.CACHE_MODE.SERVER_FIRST);
        }
    }   
});

// The Contact Collection
var ContactCollection = Force.SObjectCollection.extend({
    model: Contact,
    fieldlist: ["Id", "Name"],
    cache: function() { return App.caches.Contacts;}, 
});

// Fetch the records - assume over 2000 contact records
contacts = new ContactCollection();
contacts.config = {type:"soql", query:"SELECT Id, Name FROM Contact"};
contacts.fetch({
    success: function (data) {
     if (data.hasMore()) {
      // how can I use data.getMore()? I get 'RangeError: Maximum call stack size exceeded'
     }                    
    }                   
});

Many Thanks
  • January 21, 2014
  • Like
  • 1