Hi,
Here we are going to
see how to pass data from flow to plugin(class) and how to pass data from
plugin(class) to flow.
For this we need to
implement the "process.plugin" interface as shown below.If we write a
class which implements the "Process.Plugin" interface then
automatically it will appear in the flow under Apex Plugins in
palette.Then we can use this plugin in anywhere of flow. The following class is
a small example for to get values from from flow to class through input
parameters and passing data from class to flow variables through output parameters.
// Flow class
global class flowChat
implements Process.Plugin {
// The main method to
be implemented. The Flow calls this at runtime.
global
Process.PluginResult invoke(Process.PluginRequest request) {
// Get the subject of the Chatter post from the flow
String AccountName= (String) request.inputParameters.get('Name');
String Phone= (String) request.inputParameters.get('Phone');
// Use the Chatter APIs to post it to the current user's feed
Account actobj=new Account();
actobj.name=AccountName;
actobj.phone=Phone;
insert actobj;
// return to Flow
Map<String,Object> result = new Map<String,Object>();
result.put('AccountId','Account Id:'+actobj.id);//Setting value to
output Parameter
return new Process.PluginResult(result);
}
//
Returns the describe information for the interface
global
Process.PluginDescribeResult describe() {
Process.PluginDescribeResult result = new
Process.PluginDescribeResult();
//by using the below Name,Tag of result we can change tag name and
plugin name in flow
//these are optional
result.Name = 'flowchatplugin';//it will appear as plugin name
result.Tag ='chat';//it will appear as tag like data,logic in flow
//if we do not specify the tag name will be Apex PLUG-INS and Name will
be class Name
result.inputParameters = new
List<Process.PluginDescribeResult.InputParameter>{
new
Process.PluginDescribeResult.InputParameter('Name',
Process.PluginDescribeResult.ParameterType.STRING, true) ,
new
Process.PluginDescribeResult.InputParameter('Phone',
Process.PluginDescribeResult.ParameterType.STRING,
true)
};
result.outputParameters = new
List<Process.PluginDescribeResult.OutputParameter>{
new
Process.PluginDescribeResult.OutputParameter('AccountId',
Process.PluginDescribeResult.ParameterType.STRING)
};
return result;
}
}
When we implement the
class as shown above then plugin will appear in the flow as shown below.
After getting this
plugin we can drag and drop to right panel and pass values to input parameters
as shown below
If we want to pass
data from class to flow then we need to define output parameters as in the
class above.
After that we can pass
data from class to variable in flow as shown below.
After finishing all
the things in flow run flow now.
Now we can get
Acccountid from class to flow as shown in below.