[SalesForce] Salesforce limit of synchronous rest service

I have to implement in salesforce many inbound synchronous rest services.

What are the salesforce limits that I have to consider?

I found only the following: API Requests. A long-running API request is one that takes over 20 seconds. Salesforce allows only 25 to run at a time in an org.. For this limit salesforce cannot receive more than 25 concurrent calls with processing longer than 20 seconds. Is it right?

Moreover, can an inbound rest service perform a callout?
I know that exists Apex limit of 10 synchronous requests that last longer than five seconds, is it possible to use the Continuation for a callout started from a rest service? Using the Continuation, the callout execution time is added to time execution of the inbound call transaction?

I clarify the scenario:
A system "A" calls a Rest Resource on my Salesforce org. In the Rest Resource class I have a method that has to call another system "B" to retrieve some data. Then I have to send a response to the inbound calling system "A" using the data I retieved from "B".

Update:
I created the following rest resource in my Developer Edition (where the Concurrent Api request limit is 5).
I don't understand why I don't receive the "Concurrent API request limit Exception" by invoking 30 simultaneous post requests with secondSleepTime=100
(I receive every httpresponse after 100 seconds).

@RestResource(urlMapping='/TEST/*')
global with sharing class MyRestResource {

@HttpPost
global static String doPost(String secondSleepTime,String callName) {
    try{
        System.debug('@@@ START callName='+callName);
        Long startTime = DateTime.now().getTime();
        Integer secSleepTime=Integer.valueOf(secondSleepTime);
        MyRestResource.sleep(secSleepTime);
        Long finishTime = DateTime.now().getTime();
        System.debug('@@@ END callName='+callName);
        return String.valueOf(finishTime-startTime);
    }
    catch (Exception e)
    {
        System.debug('@@@ Exception callName='+callName+ 'Exception='+e.getStackTraceString());
    }
    return null;
}

public static void sleep(Integer sleepSeconds) {
    Long startTS = System.currentTimeMillis();
    HttpRequest req = new HttpRequest();
    req.setEndpoint('http://1.cuzillion.com/bin/resource.cgi?sleep=' + sleepSeconds);
    req.setMethod('GET');
    Http http = new Http();
    req.setTimeout(120000);
    HTTPResponse res = http.send(req);
    Long duration = System.currentTimeMillis() - startTS;
    System.debug('Duration: ' + duration + 'ms');
}

Best Answer

Yes, You cannot make more than 25 Long running API calls. It will stop all transactions after 26th till the running 25 calls leave resources for next calls. Its Governor limit.

Can an inbound rest service perform a callout? Yes it can, just a caveat, if the calling system is SF, Your System is SF and then you call to other system which is also SF then its not allowed.

If you are sure that the external calls you are making your inbound service will take less time then it should be fine, If you cant make sure of that then I would advise, moving the outbound call from inbound webservices to future/queuable method.

Can I use continuation? Well Continuation is just only for Visualforce(Or when there is a UI).As you dont have SF ui you cannot use it. Future/Queuable is your best bet

Edit: Concurent Limit for API calls

enter image description here

Concurrent Limit for Other Synchronous Transaction eg: Button CLick, trigger, VF page etc:

enter image description here

Source: http://resources.docs.salesforce.com/208/21/en-us/sfdc/pdf/salesforce_app_limits_cheatsheet.pdf

Related Topic