Flows and Plugins in Salesforce

Learn All About Flows and Plugins in Salesforce | The Developer Guide

Flows

When the process involves the number of pages when the data need to be transferred between the pages. We prefer to uses flows.

Plugin

Plugin is a built-in interface that allows you to write business logic and to pass data between your organization and a specified flow. 

Advertisement

Process Namespace

These are the interfaces and classes in the Process namespace.

  • Plugin Interface - This interface allows us to pass data between the organization and the specified flow.
  • PluginDescribeResult Class  - This class describes the input and output parameters of the Process.PluginResult.
  • PluginDescribeResult.InputParameter Class - This class describe the input parameters of Process.PluginResult.
  • PluginDescribeResult.OutputParameter Class - This class describes the output parameter for Process.PluginResult.
  • PluginRequest Class - This class passes the input parameters from the class that implements the Process.Plugin interface to the flow.
  • PluginResult Class - This class returns output parameters from the class that implements the Process.Plugin interface to the flow.

Process.Plugindescriberesult:

This class contains all the properties of all the list of input/ouput parameters.  

Public class plugindescriberesult{ List<process.plugindescriberesult.inputparameter> inputparameters; List<process.plugindescriberesult.outputparameter> outputparameters; }

dont miss out iconDon't forget to check out: Flow Builder in Salesforce | The Ultimate Developer Guide

Process.plugindescriberesult.inputparameter

This class contains all the input parameters.

process.plugindescriberesult.inputparameter(param1,param2,param3);  

param1: name of input parameter param2: datatype of input parameter param3: required value/not required value.\  

Example:

process.plugindescriberesult.inputparameter ip1= new process.plugindescriberesult.inputparameter(‘Exp’, process.plugindescriberesult.inputparameter.decimal,true);   list<process.plugindescriberesult.inputparameter> inputs= new list<process.plugindescriberesult.inputparameter>{ip1,ip2}

Process.plugindescriberesult.outputparameter

This class contains all the output parameters.

process.plugindescriberesult.outputparameter(param1,param2);  

param1: name of output parameter param2: datatype of output parameter  

Example:

process.plugindescriberesult.outputparameter op1= new process.plugindescriberesult. outputparameter(‘Exp’, process.plugindescriberesult. outputparameter.decimal);   list<process.plugindescriberesult. outputparameter> outputs= new list<process.plugindescriberesult. outputparameter>{op1,op2}

Process.pluginrequest

This class will gives information about all the input parameters we have received from flow.  

Public class process.pluginrequest { Map<string,object> inputparameters;  } Example: Process.pluginrequest request= new process.pluginrequest(); String city=request.inputparameter.get(‘city’); Decimal exp=request.inputparameter.get(‘exp’);

Process.pluginresult.

This class will give information about all the output parameters we have received from Plugin.

Public class process.pluginresult {
    Map<string,object> outputparameters;
}

Example:

Process.pluginresult result= new process.pluginresult();

Decimal bonus=result.outputparameter.get(‘bonus’);

Decimal salary=result.outputparameter.get(‘salary’);

dont miss out iconCheck out another amazing blog by Kirandeep here: Learn All About Standard Controllers in Salesforce | The Developer Guide

Example 1: Create a flow to capture experience and salary in the first screen, pass the captured values to the Plugin for calculation of bonus and total and display the output in the final screen.

public class PluginExample3 implements Process.Plugin {
    public Process.PluginResult invoke(Process.PluginRequest request){
        Decimal salary=(Decimal)request.inputparameters.get('salary');
        Decimal exp=(Decimal)request.inputparameters.get('exp');
        Decimal bonus,total;
        if( exp >3){
            bonus=(salary*15)/100;
            total=bonus+salary;
        }
        else{
            bonus=(salary*10)/100;
            total=bonus+salary;
        }
        Map<String,Object> outputMap=new Map<String,Object>();
        outputMap.put('total',total);
        outputMap.put('bonus',bonus);
        Process.PluginResult result=new Process.PluginResult(outputMap); return result;
    }
    public Process.PluginDescribeResult describe(){ Process.PluginDescribeResult result=new Process.PluginDescribeResult();
        Process.PluginDescribeResult.Inputparameter ip1=new Process.PluginDescribeResult.inputParameter('salary',Process.PluginDescribeResult.ParameterTyp e.Decimal,true);
        Process.PluginDescribeResult.Inputparameter ip2=new Process.PluginDescribeResult.inputparameter('exp',Process.PluginDescribeResult.parametertype. Decimal,true);
        Process.PluginDescribeResult.Outputparameter op1=new Process.PluginDescribeResult.outputparameter('total',Process.PluginDescribeResult.Parametertyp e.Decimal);
        Process.PluginDescribeResult.Outputparameter op2=new Process.PluginDescribeResult.Outputparameter('bonus',Process.PluginDescribeResult.ParameterT ype.Decimal);
        List<Process.PluginDescribeResult.Inputparameter> inputs =new List<Process.PluginDescribeResult.Inputparameter>{ip1,ip2};
        List<Process.PluginDescribeResult.Outputparameter> outputs=new List<Process.PluginDescribeResult.Outputparameter>{op1,op2};
        result.inputparameters=inputs;
        result.outputparameters=outputs;
        return result;
    }
}

 

Responses

Popular Salesforce Blogs