Is there a way to change the batch size of an ajax toolkit query on the visualforce page itself? I'm working on a proof of concept for a front end only dynamic search and It's working well, but I'm trying to minimize the number of api calls made for larger record sets. The ultimate goal is no controller at all.

Here's my code for the query itself:

            var query = "Select Name, Contract__c From Asset_Information__c Order By Name";

            var recordBuild = [];

            // test multi return
            var queryMore = true;
            var result = sforce.connection.query(query);

            while(queryMore) {
                var recordWhile = result.getArray('records');
                recordBuild = recordBuild.concat(recordWhile);
                if(result.done == "true") {
                    queryMore = false;
                } else {
                    // console.log(result);
                    result = sforce.connection.queryMore(result.queryLocator);
                // console.log(recordBuild);

        // Remoting carryover
        for(record in recordBuild) {
            var obj = {};
            if(recordBuild[record].Name != null) {
                obj.Name = recordBuild[record].Name;

            if(recordBuild[record].Contract__c != null) {
                obj.Contract__c = recordBuild[record].Contract__c;

        // console.log(records2);

        var records = records3;

As outlined in the SOAP Header Options page, use this code:

sforce.connection.batchSize = 2000;

2000 is the maximum legal size, but may be made smaller depending on the fields/records retrieved. This should reduce your API usage by up to 90%.

| improve this answer | |
  • That's the ticket. I spent a few hours looking for this page yesterday. – Fred O'Hara Jun 22 '16 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.