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.Plugin
apex 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
InvocableMethod
is 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);
}