[Solved] Implement pagination on APEX REST Endpoints

J. Schreiber Asks: Implement pagination on APEX REST Endpoints
I am working on a Apex REST framework that acts as an abstraction layer to make it easier for all our other systems to consume data from salesforce (i.e. consistent naming scheme for field names, abstraction for complex filters, pre-filtered lists, different representations for the same SObjects under differend endpoints, etc) compared to the standard REST Api.

However, I struggle with implementing proper pagination. The usual approach to use limit & offset as query parameters does not seem to work, since we have way over 50k records in certain SObjects, but the SOQL OFFSET only allows a maximum value of 2000.

I read about SOQL in for-Loops, which internally “utilizes SOAP query() and queryMore()”, but I have not been able to implement this functionality with Apex directly.

How to implement pagination? I don’t necessarily need limit/offset, if there are better patterns to utilize standard platform functionality, I would be very happy to use them.

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.