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
Nagesh SNagesh S 

Handling the error transactions in Rest callouts

Hi Guys,
I have new to Rest Integration and I have requirement to implement the process to consume the external rest webservices and make the callout whenever a case has been created in salesforce. For this i have creeated apex class with future methosds to handle the callouts and calling the methods from trigger.
Now I have to handle the cases that are not proccesed or errored due to some server errors. 
Can any one suggest me the best way to handle the error callout transactions ? 
Appriciated your great suggestions.

Thanks,
Santosh Bompally 8Santosh Bompally 8
Add a ResponseHandler. Ideal way is to create a custom object by some name like Integration failures and inserting a record into it everytime an error comesback.  Are you looking for anything in specific ??

Use this as reference. 
 
//Future annotation to mark the method as async.
  @Future(callout=true)
  public static void callwebservice(String id) {

    //construct an HTTP request
    HttpRequest req = new HttpRequest();
    req.setEndpoint('http://example.com/tutorial/sfdc/sample1/data.txt');</a>
    req.setMethod('POST');
    req.setbody(somejson);
    //send the request
    Http http = new Http();
    HttpResponse res = http.send(req);

    //check the response
    if (res.getStatusCode() == 200) {
   // Add success actions, There can be multiple Successcodes, generally all 200's are success
      
    } else {
    // Insert a record in integration logs. 
    } 
  }







 
Nagesh SNagesh S
Hi Santosh,

Thanks for response.
I can insert recordID into a custom object but I dont want to stop there. Im looking for the best way to process them agian without user interaction. 
Now Im having the option as recreate the record so it will follow the Callout process.

Thanks,