Is it possible to set either the @InvocableMethod or Process.Plugin with a @future(callout=true)?
My problem (bear with me):
- I have a trigger that calls a class
- the class creates an object and calls another class
- this class creates more objects and calls a flow
- the flow (is quite lengthy) eventually fires off a
Process.Pluginapex class, that has input and output data and calls a webservice.
When I call the flow normally from the Trigger I get error:
System.CalloutException: Callout from triggers are currently not supported.
So I attempt to make the call out a future and I get error:
Future methods do not support parameter type of
Process.PluginRequest
Which then leads me to question if I should try to re-write my Process.Plugin class to an Invocable class. When I create a mock Invocable class with the @future annotation I get error:
The only annotation that can be used with
InvocableMethodis Deprecated
The greater question is- is there another way to call a callout from a trigger without using the @future annotation?
I found this question but it is from 2012.
UPDATE: follow up question:
//The main method to be implemented. The Flow calls this at runtime.
global class FlowToWebservice_Class implements Process.Plugin {
public static Map<String,Object> result = new Map<String, Object>();
global Process.PluginResult invoke(Process.PluginRequest request){
varProcessName = (String)request.inputParameters.get('varProcessName');
varCreditReviewId = (String)request.inputParameters.get('varCreditReviewId');
callWebService(varProcessName , varCreditReviewId);
return new Process.PluginResult(result);
}
@future(callout=true)
global static void callWebService(String processName, String crId) {
req = new HttpRequest();
req.setEndpoint(endpointURL);
req.setMethod('POST');
req.setBody(k);
req.setHeader('Content-Type', 'application/json');
req.setTimeout(120000);
string d = getAuth();
req.setheader('Authorization', d);
try {
Http h = new Http();
res = h.send(req);
JSONParser parser = JSON.createParser(res.getBody());
while (parser.nextToken() != null) {
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'Status')) {
...
}
}
}
catch (System.CalloutException z) {
system.debug('z: ' + z);
}
//output params
result = new Map<String,Object>();
result.put('varResult',finalDecision);
result.put('varROSID', relatedOppSearchId);
result.put('varDeclineReason', declineReason);
}
global static Process.PluginResult invoke(Process.PluginRequest request) {callWebService(...);}, I am trying it out now... – Olivia Dec 19 '17 at 18:30callWebService(), I can't have a return statement because it is afuturemethod, and when I update a static variable with the returned parameters within the future method, the values do not get carried over to the return statement on theinvoke()method. How would I go about passing back the output parameters? See updates for better explanation. – Olivia Jan 12 '18 at 00:07@futurecontext so that you don't get recursion errors (you can't call a future method from a future method). – sfdcfox Jan 12 '18 at 15:35