0

Using the REST API, I am querying an object that returns around 11000 records. The REST API allows only for a maximum of 2000 records to be returned at once, with a link for the next 2000. Instead of this, I get 1000 records as a result to my query with a link for the next 1000 and so on. The problem is that even though the response returns 1000 records at a time, the totalSize node for each result page has a value of 2000, which is wrong, as it should be 1000. This is causing problems in my code and it would be easier to force REST API to return 2000 records at once instead of 1000. Is this possible or is this a Salesforce bug?

1

totalSize should be the total number of results, not just the number of results in the current batch. The number of results returned per "page" will depend on the number and type of fields selected. While you can "recommend" that up to 2,000 results be returned, the API may adjust this to a lower value if it would cause an extremely large payload. In other words, if you want to return more than 1,000 rows, you'd need to reduce the number of fields you're selecting. As noted in the Query Options Header:

The default is 2,000; the minimum is 200, and the maximum is 2,000. There is no guarantee that the requested batch size is the actual batch size. Changes are made as necessary to maximize performance.

Your code basically needs to loop while done is false, and use the nextRecordsUrl to get the next batch of records.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.