I have 535 Contact records in my Developer account. I am finding that the following query:
SELECT Id,FirstName,Lastname FROM Contact LIMIT 205 OFFSET 190
returns 200 records from Database.query(), while this query:
SELECT Id,FirstName,Lastname FROM Contact LIMIT 199 OFFSET 190
returns 199. I suspect there is an implicit 200 maximum on the value for LIMIT, but I can’t find it documented anywhere, and no error is raised when I use these higher values.
Answer
The LIMIT
clause has no limit in and of itself. It’s limited to the context in which it’s used. If it’s used in Apex code it’s limited to the total governor limit for SOQL rows, which is currently 50,000. If it’s used in a query via the Web Service API then there is no limit.
The issue you’re running into appears solely to be an issue with using the OFFSET
clause and LIMIT
together.
Attribution
Source : Link , Question Author : Jeff Trull , Answer Author : E.J. Wilburn