is it possible to set the batch size for queries via REST API? The REST API Query documentation http://www.salesforce.com/us/developer/docs/api_rest/Content/resources_query.htm states For more information on query batch sizes, see Changing the Batch Size in Queries in the SOAP API Developer's Guide. . I know that I can set the QueryOptions via SOAP header, but is it possible to set it for REST somehow?

C# Sample for the SOAP API

private void queryOptionsSample() 
    binding.QueryOptionsValue = new QueryOptions();

    binding.QueryOptionsValue.batchSize = 250;
    binding.QueryOptionsValue.batchSizeSpecified = true;

Any help and example would be much appreciated!


3 Answers 3


We can use this header to set the batchSize for REST API

Sforce-Query-Options: batchSize=1000

Refer https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/headers_queryoptions.htm for more details


Default value for REST API is 2000. How it can be reduced to say 100 records

I believe you cannot limit it 100. From the documentation, the minimum size is 200 and maximum is 2000.

Field values

batchSize — A numeric value that specifies the number of records returned for a query request. Child objects count toward the number of records for the batch size. For example, in relationship queries, multiple child objects are returned per parent row returned. The default is 2,000; the minimum is 200, and the maximum is 2,000.

There is no guarantee that the requested batch size is the actual batch size. Changes are made as necessary to maximize performance.

Example Sforce-Query-Options: batchSize=1000

Also there is no guarantee that you will always get the size you have asked for as the SFDC Query Optimizer may reduce the number of records fetched to improve performance.

Since the standard API does not guarantees the size limit, what you can do is

  1. Create your own web service and use Offset in your query.
  2. Create your own service and use autonumbers to query data.


Reading this document we can do a batch query in REST API too

If the initial query returns only part of the results, the end of the response will contain a field called nextRecordsUrl.

For example, you might find this attribute at the end of your query: "nextRecordsUrl" : "/services/data/v20.0/query/01gD0000002HU6KIAW-2000"

In such cases, request the next batch of records and repeat until all records have been retrieved. These requests use nextRecordsUrl, and do not include any parameters.


Other way would be to build apex REST SERVICE yourself using OFFSET in query .

  • 2
    yes, but whats not the question. I am after changing the batch size of the query, so instead of receiving 2000 records per page, I just want to receive 150, without using offset
    – Seb Wagner
    Commented Aug 14, 2013 at 8:37
  • I think its by default 500 or so .It chunks depending on the size .Other way would be to build apex REST SERVICE yourself using OFFSET . Commented Aug 14, 2013 at 8:39
  • Default value for REST API is 2000. How it can be reduced to say 100 records Commented Mar 3, 2016 at 6:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .