How to specify BatchSize in Rest API SOQL call, I tried it as per salesforce documentation and its not working ?

Note - I know you can do this using offset, but I wanted to explore if its possible using BatchSize.

Sample Code (I added this code in visualforce page) -

jQuery(document).ready(function($) {
  // Pull 10 Accounts via the REST API
      beforeSend: function(xhr) {
        // Set the OAuth header from the session ID
        xhr.setRequestHeader('Authorization', 'Bearer {!$Api.Session_ID}');
        xhr.setRequestHeader('batchSize', '5');            
      success: function(response) {
        // We got 'em - append our records to the HTML list
        $.each(response.records, function(index, record) {
      error: function(jqXHR, textStatus, errorThrown) {
        // Oops - what went wrong?
        alert(jqXHR.status + ': ' + errorThrown);

This code still gives me 10 accounts instead of 5 accounts.

  1. The header is called Sforce-Query-Options, specified like this:

    Sforce-Query-Options: batchSize=1000
  2. You can't specify a batch size of less than 200, or greater than 2000. Also, it is only a "hint" and may be adjusted/ignored at the server's discretion.

  • Thanks for a lot for your answer, it worked well for me. – Prafulla Patil Oct 31 '14 at 22:03
  • How do I do this for the Bulk API? – Hussain Tamboli Nov 3 '15 at 7:30
  • 1
    Also, to add on to your 'at server's discretion' comment, it seems to ignore the batch size in some scenarios, found this in the SOAP API documentation but seems to apply to REST as well The batch size will be no more than 200 if the SOQL statement selects two or more custom fields of type long text. – Phil B Apr 12 '17 at 13:59

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.