Pagination In Custom APEX REST Endpoint
In my custom APEX REST endpoint, I want to have the exact same pagination as the SFDC REST API. Is there an easier way to achieve this than implementing the logic from scratch? I would love to just extend abstract base class that holds all this logic and is used by the SFDC REST API as well. Or something similarly convenient, that doesn't involve me re-inventing the wheel.
Thanks in advance, Peter
Answer
Unfortunately, you won't find a "built-in" paging mechanism in the Apex REST framework.
However, basic paging can be achieved using the LIMIT and OFFSET clauses in your underlying SOQL query.
I'm assuming you're going to apply this to a custom GET
request, and one of the drawbacks of this is the lack of a server-side cursor. So, in order to maintain your paging context, you would need to pass an updated offset value on each subsequent query, depending on which way the paging is going.
Also, I would highly consider applying a permanent ordering clause for the SOQL query, as well. Though you can mostly rely on getting the same results in the same order without one, it's not guaranteed to be consistent; better safe than sorry.
Related Questions
- → Is It Possible To Use An External Database For User Data & Login Credentials With Shopify?
- → Change Database Source Depending on Login Credentials
- → JSON iteration in JAVA using jettison library
- → SyntaxError: Cannot use import statement outside a module in JEST LWC
- → Salesforce REST API query - URL limit
- → Regex to mask characters except first two digits in Java
- → How to make Multilevel Drop down navigation in wordpress theme?
- → laravel salesforce require_once?
- → Getting "INVALID_FIELD_FOR_INSERT_UPDATE" error message when try to update Salesforce Contact objet via Java(EnterpriseWSDL)
- → Infinite loop on ComponentWillMount ReactJS
- → how to get current date in MOMENT.JS Dynamic
- → Why i can't add Approval record row into the CR ticket
- → Pagination In Custom APEX REST Endpoint