0

I have created the APEX REST API to fetch the data from Salesforce and send it to the external resource. For this API I have included one parameter called maxLimit which restrict the no of data (rows) returned in API response. for e.g. if maxLimit is given as 30 only 30 records will be returned. Now what I have added as a logic that if maxLimit is not specified I am taking maxLimit as 60 to avoid performance issue.

Now, my concern is I need to remove this default maxLimit logic, i.e. if maxLimit is null (Not Specified) I need to fetch and send all the data from Salesforce to an external system. I want to ask that if I remove this logic what will be the effects? Is there any Limit on API response?

  • I believe you are making a SOQL query in your REST API to return the results. In this case, the same governor limits as applicable to APEX should apply in this scenario i.e. 50000 rows in one transaction. – Shailesh Deshpande Feb 12 '18 at 6:54
  • Thanks, @ShaileshDeshpande for your response. Yes, you are right I am making a SOQL query to return the results. Is there any performance issue will be there if I send all the records? And one more thing when I am calling the API through Postman I am getting only 200 records, do you have any Idea why I am getting only 200 records? – Nirav Shah Feb 12 '18 at 7:06
  • Have you created a rest API class or you are using Salesforce standard rest query API? Because the default limit for Salesforce standard rest API is 200 and it can be extended upto 2000. If you are using standard API then you will not run into any SOQL query row limits. – manjit5190 Feb 12 '18 at 14:27
  • @manjit_singh I have created rest API class from which I am querying the records – Nirav Shah Feb 14 '18 at 6:15
1

Yes All governor limits are applied here as well. TO Add LIMIT dynamically you can use getLimitQueryRows() of LIMIT class in Salesforce.

Also the 200 records you are getting the expected behavior. In this case you are getting one parameter nextRecordsUrl

"nextRecordsUrl" : "/services/data/v20.0/query/01gD0000002HU6KIAW-2000"

You need to add this in request to get the next chunk of record.

https://yourInstance.salesforce.com/services/data/v20.0/query/01gD0000002HU6KIAW-2000 -H "Authorization: Bearer token"

And final result will be like

{
    "done" : true,
    "totalSize" : 3214,
    "records" : [...]
}

Execute a SOQL Query

0

The limit which applies here is Limits.getLimitQueryRows(), which is 50,000. You can also see that information for yourself in the documentation on Apex Governor Limits.

Note that you may have already consumed some of this governor. You can dynamically set the limit to the maximum remaining query rows as follows:

if (maxLimit == null)
{
    maxLimit = Limits.getLimitQueryRows() - Limits.getQueryRows();
}

As long as you don't have a query in a loop you shouldn't exceed your limit for total number of queries. Same goes for CPU time, etc. You can write code so inefficient you will consume more resources than you have available.

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.