I want to create a custom Rest web service,
it would execute some logic and return max 5000 records.

What is the best practice for:
1. Setup data chunks.
2. Notice client side to query more chunks.
3. Result preparation. Could I execute and prepare results only once and store at somewhere, or I must execute each time for the subset of results?
Furthermore, if result size is changed (deleted by another user) during the communication, how to handle with that?

Any help would be appreciated.

1 Answer 1


REST API Query results are truncated and only 2000 records are returned at once. Have to use nextRecordsUrl to get the next set of records. Salesforce documentation explains it all: https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_query.htm

If there is a method that takes care of a functionality and returns a set of records, there isn't a limit of 2000 records. As far as the governor limits are not impacted you should be good.

Here is a good example on how to expose a class as rest service: https://developer.salesforce.com/docs/atlas.en-us.apex_workbook.meta/apex_workbook/apex_rest_1.htm

If the records are deleted after the rest call, it has to be handled as a separate callout.

  • nextRecordsUrl is for Rest API, my question is "Custom Rest Web Service" ,which has not such nextRecordsUrl, please tell me how to deal with that.
    – ling
    Oct 26, 2015 at 7:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .