function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
odieodie 

webservices query

Hi,

 

I am querying custom objects in SF using webservices. Is there a way I can fetch only the nth batch of records from a select statement.

 

For example -there are 100 results for "select id from account order by created date". I want only results numbering 21-30.  Is there any way I can achieve this?

 

There is a limit command I can use with the select statement, but that only gives me the first n records.

 

Thanks,

Odie

Richie DRichie D

I think you may have to use 'limit 10' and pass back in the last item you received so you get something like

[select id, createdDate from account where createdDate >:myLastDateReturned order by created date limit 10]

 

Might be other ways to do it so lets see what others come up with!

R. 

jpizzalajpizzala

I don't believe there is a way to directly grab ONLY records 21 - 30.  However, by utilizing the QueryMore method along with batch limits, you should be able to query until you get all the desired records, then exit the query once you get to this point.

 

You can read about QueryMore here

 

The batch limitation is set on the connection binding.  Basically, pass in the following line (for Java) to limit the number of records returned:

 

 

QueryOptions queryOptions = new QueryOptions();
queryOptions.setBatchSize( 10 );
binding.setHeader( new SforceServiceLocator().getServiceName().getNamespaceURI(), "QueryOptions", queryOptions );

 

Where the int 10 is the number of records you want returned for each QueryMore request.

 

 

If you don't want to mess with the batch limit, just leave it at the default value and use iterative logic to extract the records you want.