---
schema_version: "1"
id: 8cc168e14c68a0a2b3f5d12e4ad25e7de9d85a4afd3b547f3e4038aed6af7d9d
title: Change the Batch Size in Queries
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/salesforce-soql-sosl/guides/soql-sosl/sforce-api-calls-soql-changing-batch-size.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-soql-sosl/guide/sforce-api-calls-soql-changing-batch-size.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 72a67c0a9f6ddbdcb1b68aa83b93a78515c08e0f11943cd502d4a2afd5d6632a
products:
  - SOQL and SOSL Reference
  - Platform Developer Content
---

# 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](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/headers_queryoptions.htm) to change the number of results returned in a single query. For more information, see [Query](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_query.htm) 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()](https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_query.htm) in the _SOAP API Developer Guide_.

**note:** 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.

## WSC (Java) Example to Set the Batch Size

The following Java WSC (Java) code example sets the batch size to 250records.

<!-- otherprops: java -->

```codesegment
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.

<!-- otherprops: c_sharp -->

```codesegment
private void queryOptionsSample()
{
    binding.QueryOptionsValue = new QueryOptions();

    binding.QueryOptionsValue.batchSize = 250;
    binding.QueryOptionsValue.batchSizeSpecified = true;
}

```
