How to fetch more than 2000 records through SOQL .... Is there something query more ?
Asked
Active
Viewed 3,210 times
2
-
Is SOQL SalesForce.com Object Query Language? If so, did you mean to tag this as Adobe Flex? – JeffryHouser Jun 24 '10 at 18:55
-
I retagged the question to SOQL – JeffryHouser Jun 24 '10 at 18:55
2 Answers
5
call queryMore with the queryLocator provided in the first set of results, keep calling it with the next queryLocator until the done flag is true. See the Web Services API docs for more info.

superfell
- 18,780
- 4
- 59
- 81
1
You can actually do this manually as well if you order by id and then query again with "where id > : idPrevious". If you try this just as I've typed it you'll hit a problem however, you can't use > and < with id fields. There is a simple work around for this though, just create a text type formula field which takes it's value from the id field. Then you can use that field in the query with no problems.
Of course if you're just looking to process loads of data then you might really be looking for Batch Apex.

Matt Lacey
- 8,227
- 35
- 58
-
but the id of sales force are not sequential i mean they are not integers !! – yatish mehta Feb 21 '12 at 13:43
-
Correct, but if you sort by ID they'll always be in the same order, so minor discrepancies could occur if data is updated while you're running through the set, but otherwise this works as you require. – Matt Lacey Feb 21 '12 at 21:59
-
where id> preivious id . ">" invalid operator on id . SO the above logic doesnt work – yatish mehta Feb 23 '12 at 08:58
-
Did you use a formula field with the value of the ID instead of the ID field itself? – Matt Lacey Feb 23 '12 at 22:48