0

From batch class we are able to connect to third party API 5times per second on an average, i am wondering is there any way to increase the callouts per second.

I am sure there may be chances

  • Timing depends on time taken in complete one cycle of data exchange. From Salesforce you cannot control. There is not way to increase frequency. But you can optimize the webservice response and request processing time so you get response quick. – Ashwani Dec 29 '15 at 9:43
  • Yes that's correct @Ashwani , is there a way to make parallel processing.. – Sunny Dec 29 '15 at 9:46
  • I have answered the second query is there a way to make parallel processing – Ashwani Dec 29 '15 at 9:53
  • Let me know if it worked for you when you get chance. – Ashwani Dec 29 '15 at 9:57
  • Thanks @Ashwani, that's working if we have UI interaction in the tramsaction. But if we try from Batch, it it not working as expected. – Sunny Dec 29 '15 at 10:00
0

You can use Apex Continuation technique. In Apex, there is away to do async callouts and process their response in parallel.

Go through following doc: Long Running Callouts

A Sample Example which you can re-use:

public with sharing class ContinuationController {
    // Unique label corresponding to the continuation
    public String requestLabel;
    // Result of callout
    public String result {get;set;}
    // Endpoint of long-running service
    private static final String LONG_RUNNING_SERVICE_URL = 
        '<Insert your service URL>';

   // Action method
    public Object startRequest() {
      // Create continuation with a timeout
      Continuation con = new Continuation(40);
      // Set callback method
      con.continuationMethod='processResponse';

      // Create callout request
      HttpRequest req = new HttpRequest();
      req.setMethod('GET');
      req.setEndpoint(LONG_RUNNING_SERVICE_URL);

      // Add callout request to continuation
      this.requestLabel = con.addHttpRequest(req);

      // Return the continuation
      return con;  
    }

    // Callback method 
    public Object processResponse() {   
      // Get the response by using the unique label
      HttpResponse response = Continuation.getResponse(this.requestLabel);
      // Set the result variable that is displayed on the Visualforce page
      this.result = response.getBody();

      // Return null to re-render the original Visualforce page
      return null;
    }
}

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.