function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ryan Werner 22Ryan Werner 22 

Exposing a REST API - Running into limit issues

We are trying to expose a service in Salesforce using Apex that external systems can call. This service is pretty simple. We will run a query against an object and create a response that returns an array of "coupon codes" stored on each account of a certain record type that has a coupon code.
basically it's just [SELECT Id, Coupon__c FROM Account WHERE Coupon__c != null]
We then will loop through the list and formulate a JSON array and return the coupon codes.
The issue here is we have more than 50,000 rows needing to be returned. So SOQL 101 is an issue. Also heap size could be an issue. We are expecting possibly up to 500,000+ accounts with coupons to be returned.
What are our options here? Should we tell our consumers to call a standard Salesforce API, similar to how you can execute queries in workbench? This would require subsequent calls to retrieve all 500,000 accounts/coupons though, right? Like a query more type of thing?
Also now that we are exposing APIs from Salesforce, I know we have a 24 hour API call limit. Is there a concurrent limit? If we are allowed say, 5,000,000 calls over a 24 hour period, what happens in 4,000,000 all come at the same time? How will the system respond?
Any help would be appreciated. Thanks!
Ankit SehgalAnkit Sehgal

Hi Ryan,

According to API Request Limits and Allocations ( -

Concurrent API Request Limits:
Limits for various types of orgs for concurrent requests (calls) with a duration of 20 seconds or longer:
Developer Edition and Trial orgs: 5
Production orgs and Sandboxes: 25


Ryan Werner 22Ryan Werner 22
Hi Ankit-

The limitation you mention is for concurrent long-running Apex transactions. This has nothing to do directly with API calls. I'm wondering if we expose a Apex REST API endpoint, if this endpoint is called 1 million times in 1 second, will Salesforce be able to respond to all of them? Even if the transactions themselves only take a second to process and return?