You need to sign in to do that
Don't have an account?
davidleckenby
I need to pass back the response result (String) from a Web Service call class to a trigger class
Hi - I am wanting to pass back the response string from this Webservice class, which is void by nature, to the trigger that is calling it. I have tried various methods by using a primitive string reference and also creating a new class with s string variable inside it but havent been able to get the string result back. Below is the code for the Webservice class.
This is the call from the trigger
public with sharing class ELO_Webservice { @future (callout=true) public static void CallWebService(String body, String respStr) { Http http = new Http(); HttpRequest request = new HttpRequest(); request.setEndpoint(); request.setMethod('POST'); request.setHeader('Content-Type', 'application/json;charset=UTF-8'); // Set the body as a JSON object //System.debug(body); request.setBody(body); '); HttpResponse response = http.send(request); // Parse the JSON response if (response.getStatusCode() != 200) { System.debug('The status code returned was not expected: ' + response.getStatusCode() + ' ' + response.getStatus()); } else { System.debug(response.getBody()); } respStr.responsestr = response.getBody(); System.debug('responsestr = ' + respStr.responsestr); }
This is the call from the trigger
ELO_Webservice.CallWebService(body, eResponse.responsestr);Hope this is clear. Many thanks
Callouts cannot be made from triggers as that would hold up the database transaction until the callout completed, which can be up to 120 seconds from a limits perspective. the callout from a trigger is to schedule it to run asynchronously,so you can't wait for a response from the callout as that would require the transaction to stall until it completes, which is the reason that synchronous callouts aren't allowed.
There are the options
All Answers
Callouts cannot be made from triggers as that would hold up the database transaction until the callout completed, which can be up to 120 seconds from a limits perspective. the callout from a trigger is to schedule it to run asynchronously,so you can't wait for a response from the callout as that would require the transaction to stall until it completes, which is the reason that synchronous callouts aren't allowed.
There are the options