Priya
Priya

Reputation: 29

SOQL Query to fetch more than 2000 records

How to fetch more than 2000 records through SOQL .... Is there something query more ?

Upvotes: 2

Views: 3509

Answers (2)

Matt Lacey
Matt Lacey

Reputation: 8255

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.

Upvotes: 1

superfell
superfell

Reputation: 19040

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.

Upvotes: 5

Related Questions