Changing the Batch Size in Queries

By default, the number of rows returned in the query result object (batch size) returned in a query() or queryMore() call is set to 500. Client applications can change this setting by specifying the batch size in the call QueryOptions portion of the SOAP header before invoking the query() call. The maximum batch size is 2,000 records. However this setting is only a suggestion. There is no guarantee that the requested batch size will be the actual batch size. This is done to maximize performance.

Note
The batch size will be no more than 200 if the SOQL statement selects two or more custom fields of type long text. This is to prevent large SOAP messages from being returned.

The following sample Java (Axis) code demonstrates setting the batch size to two hundred and fifty (250) records.

QueryOptions qo = new QueryOptions();

qo.setBatchSize(new Integer(250));

binding.setHeader(new SforceServiceLocator().getServiceName().getNamespaceURI(), 
                     "QueryOptions", qo);

The following sample C# (.NET) code demonstrates setting the batch size to two hundred and fifty (250) records.

binding.QueryOptionsValue = new QueryOptions();

binding.QueryOptionsValue.batchSize = 250;
binding.QueryOptionsValue.batchSizeSpecified = true;
© Copyright 2000-2008 salesforce.com, inc. All rights reserved.
Various trademarks held by their respective owners.