+ Start a Discussion
astroastro 

Help setting an appropriate batch size for a query

I am facing a problem when querying for records where I am not returning all records.

 

More specificaly, I have a query which is returning approx. 11144 results.  I have set the batchSize to 250 and so ultimately only 11000 records are returned.  I would  assume this is because once 11000 is hit, there is less records left to query than the batchsize.  My question is, how do I dynamically set the batchSize to make sure I return all records?  I understand i could do this mathematically but was wondering if there was a more straightforward way, or if I am misunderstanding how to use this function.

 

Thanks 

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell
query/queryMore will return all the rows from your query, regardless of the number of rows, and your batch size setting, if you set the batch size to 200, and the last set of rows is 22, you'll get those last 22 rows. It sounds like you might be checking the done flag in the queryResult structure before processing the records in that query result. (which would mean you always miss the last set).

All Answers

SuperfellSuperfell
query/queryMore will return all the rows from your query, regardless of the number of rows, and your batch size setting, if you set the batch size to 200, and the last set of rows is 22, you'll get those last 22 rows. It sounds like you might be checking the done flag in the queryResult structure before processing the records in that query result. (which would mean you always miss the last set).
This was selected as the best answer
astroastro

Thank's SimonF that was the problem.