SOQL OFFSET
The OFFSET
clause is used to specify the cursor or the number of records that should be skipped before returning results from the query. This clause is primarily used when we want to break the set of records into various pages, or batches.
Example: Let’s say we want to show the list of clinics on a page. And we want to apply pagination, so each page contains a maximum of 25 clinics.
The SOQL query for Page 1:
SELECT Id, Name
FROM Clinic__c
LIMIT 25
The SOQL query for Page 2:
SELECT Id, Name
FROM Clinic__c
OFFSET 25
LIMIT 25
The SOQL query for Page 3:
SELECT Id, Name
FROM Clinic__c
OFFSET 50
LIMIT 25
The SOQL query for Page n:
SELECT Id, Name
FROM Clinic__c
OFFSET 25*(n-1)
LIMIT 25
We can easily see how it is straightforward to break records using the OFFSET
clause.