Change the Batch Size in Queries

The batch size for a query determines the number of rows that are returned in the query results. You can change the batch size that’s returned in queries made using both REST API and SOAP API.

The default and the maximum for query result batch size is 2,000 records. However, to optimize performance, the returned batch size can be lower than the max or what's set in the request, based on the size and complexity of records queried.

In REST API, use the batchSize field in the query options header to change the number of results returned in a single query. For more information, see Query in the REST API Developer Guide.

In SOAP API, change the batch size in the QueryOptions header before invoking the query() call. Salesforce Web Service Connector (WSC) clients can set the batch size by calling setQueryOptions() on the connection object. For more information, see query() in the SOAP API Developer Guide.

If the SOQL statement selects two or more custom fields of type long text, the batch size can’t be greater than 200 records. This limit prevents large SOAP messages from being returned.

Note

WSC (Java) Example to Set the Batch Size

The following Java WSC (Java) code example sets the batch size to 250records.

public void queryOptionsSample() {
  connection.setQueryOptions(250);
}

C# (.NET) Example to Set the Batch Size

The following C# (.NET) code example sets the batch size to 250records.

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

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