Paginate SOQL query with LIMIT and OFFSET
Use LIMIT and OFFSET to paginate SOQL queries with ORDER BY clause.
SELECT Id, Name FROM Contact ORDER BY Name LIMIT 200 OFFSET 200
Examples:
Paginated SOQL query with WHERE clause and ORDER BY clause
SELECT Id, Name, ShippingState FROM Account WHERE ShippingState = 'CA' ORDER BY Name LIMIT 100 OFFSET 100
Notes:
LIMIT and OFFSET must appear after WHERE and/or ORDER BY clauses.
When LIMIT and OFFSET clauses are used together, LIMIT must precede OFFSET.
The maximum offset is 2000 rows.
Comments:
Always use LIMIT and OFFSET with ORDER BY clause to ensure predictable sort order from one page query to the next.