Monday 21 October 2013

Passing Data between Organization(class) and Flow Using the Process.Plugin Interface(visual workflow)

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.


Saturday 12 October 2013

Process.PluginDescribeResult Class

The Process.PluginDescribeResult class is used to determine the input parameters and output parameters needed by theProcess.PluginResult class.
Use the Process.Plugin interface describe method to dynamically provide both input and output parameters for the flow. This method returns theProcess.PluginDescribeResult class.
The Process.PluginDescribeResult class can't be used to do the following functions:
·         Queries
·         Data modification
§  Email
§  Apex nested callouts
Process.PluginDescribeResult Class and Subclass Properties
The following is the constructor for the Process.PluginDescribeResult class:
Process.PluginDescribeResult classname = new Process.PluginDescribeResult();
The following describe the properties of Process.PluginDescribeResult and its input and output parameter subclasses:
·         PluginDescribeResult Class Properties
·         PluginDescribeResult.InputParameter Class Properties
§  PluginDescribeResult.OutputParameter Class Properties
The following is the constructor of the Process.PluginDescribeResult.InputParameter class:

Process.PluginDescribeResult.InputParameter ip = new
    Process.PluginDescribeResult.InputParameter(Name,Optional_description_string,
      Process.PluginDescribeResult.ParameterType.Enum, Boolean_required);
The following is the constructor of the Process.PluginDescribeResult.OutputParameter class:
Process.PluginDescribeResult.OutputParameter op = new
    new Process.PluginDescribeResult.OutputParameter(Name,Optional description string,
       Process.PluginDescribeResult.ParameterType.Enum);
To use the Process.PluginDescribeResult class, create instances of the following additional subclasses:
·         Process.PluginDescribeResult.InputParameter
·         Process.PluginDescribeResult.OutputParameter
Process.PluginDescribeResult.InputParameter is a list of input parameters and has the following format:

Process.PluginDescribeResult.inputParameters =
      new List<Process.PluginDescribeResult.InputParameter>{
         new Process.PluginDescribeResult.InputParameter(Name,Optional_description_string,
      Process.PluginDescribeResult.ParameterType.Enum, Boolean_required)
For example:
Process.PluginDescribeResult result = new Process.PluginDescribeResult();
result.setDescription('this plugin gets the name of a user');
result.setTag ('userinfo');
result.outputParameters = new List<Process.PluginDescribeResult.OutputParameter>{
    new Process.PluginDescribeResult.OutputParameter('URL',
        Process.PluginDescribeResult.ParameterType.STRING),
Both classes take the Process.PluginDescribeResult.ParameterType Enum, which has the following values:
·         BOOLEAN
·         DATE
§  DATETIME
§  DECIMAL
§  DOUBLE
§  FLOAT
§  ID
§  INTEGER
§  LONG
§  STRING
For example:
Process.PluginDescribeResult result = new Process.PluginDescribeResult();
        result.outputParameters = new List<Process.PluginDescribeResult.OutputParameter>{
            new Process.PluginDescribeResult.OutputParameter('URL',
            Process.PluginDescribeResult.ParameterType.STRING, true),
            new Process.PluginDescribeResult.OutputParameter('STATUS',
            Process.PluginDescribeResult.ParameterType.STRING),

            };

Process.Plugin interface for cloud flow designer

Process.Plugin is a built-in interface that allows you to process data within your organization and pass it to a specified flow. The interface exposesApex as a service, which accepts input values and returns output back to the flow.
When you define an Apex class that implements the Process.Plugin interface in your organization, the Cloud Flow Designer displays the Apex class in the Palette.
Process.Plugin has the following top level classes:
·         Process.PluginRequest
·         Process.PluginResult
The Process.PluginRequest class passes input parameters from the class that implements the interface to the flow.
The Process.PluginResult class returns output parameters from the class that implements the interface to the flow.
The Process.PluginRequest class passes input parameters from a flow to the class that implements the interface.
When you’re writing Apex unit tests, you must instantiate a class and pass it in the interface invoke method. You must also create a map and use it in the constructor to pass in the parameters needed by the system.

The Process.PluginDescribeResult class is used to determine the input parameters and output parameters needed by theProcess.PluginResult plug-in.



How to include a screen flow in a Lightning Web Component

 Hi, Assume  you have a flow called "Quick Contact Creation" and API Name for the same is "Quick_Contact_Creation". To i...