Tag: Flow

Flow Invocable Actions

In this post, I will show how to use the flow Invocable Action… Actions are easy to discover and use, and also easy to understand and implement. Every button and link in Salesforce can be considered an action. A consistent Actions API and framework support the creation and distributed use of actions throughout Salesforce. Actions are available in the REST API. Invocable actions, also known as dynamic actions, can be invoked from a common endpoint in the REST API. Here we will be creating a flow and calling the flow using the REST API. The example we are taking here is returning the order and order lines items based on the order name from the auto-launched flow.

1. Create a flow 

now create a flow that will take the input argument from the rest API and return query order and order line items based on the order name.now from the flow designer create a new input variable that will collect the order name.

 

Drag and drop the fast lookup on the flow builder and Lookup the order name by passing the Order name from the inputVariable created above

OrderResult is sobject variable and adds the following fields

Now drag and drop one more Fast lookup now to query the order line items and this time we will assign the value to result variable to sobject collections.

Orderlines in the sobject collection type and return the following fields.

Connect the two fast lookups as shown below

Now save the flow of type Auto launched Flow as shown below

2. Calling Flow Actions

Now you will be able to call the flow from the invocable flow actions. Now you need to use the custom flow actions rest URI

Invokes the OrderAPIService flow

You will be able to execute the REST API from the workbench. Go to the salesforce workbench and execute the rest API as shown below

After executing the flow action, you can able to see the result as shown below

Understanding Input and Output

        Input values vary according to the input variables specified for each flow. For autolaunched flows, the input values vary according to the input variables in that flow. In this example the input variable is OrderNumber Invocable processes always require either one of the following input parameters:

  • sObjectId: The Id of the sObject record that you want the process to execute on. The record must be of the same object type as the one on which the process is defined.
  • sObject: The sObject itself that you want the process to execute on. The sObject must be of the same object type as the one on which the process is defined.

Output values vary according to the output variables specified
Flow__InterviewStatus is available for flows. Invocable processes do not have outputs. In the response, you can able to see the Flow__InterviewStatus as finished.

 

Flow Local Actions Using Lightning Components

                    Flow Local Actions Using Lightning Components allow you to execute client-side logic in your flow, build or modify custom Lightning components to use as local actions in flows. For example, get data from third-party systems without going through the Salesforce server, or open a URL in another browser tab. Once you configure the Lightning component’s markup, client-side controller, and design resource, it appears in the Cloud Flow Designer as a Local Action element. In this example, the input screen on the flow will take a country name and from there invoke the local action and return the country information from the web service.

How to add Flow Local Actions 

          Add the lightning:availableForFlowActions interface to a Lightning component to make it available as a flow action. When a component is executed as a flow action, the flow calls the invoke method in the client-side controller. Flows that include Lightning components are supported only in Lightning runtime. Lightning components that implement lightning:availableForFlowActions are available as Local Action elements in the Cloud Flow Designer. When a component is executed as a flow local action, the flow calls the invoke method in the client-side controller. To run the code asynchronously in your client-side controller, such as when you’re making an XML HTTP request (XHR), return a Promise. When the method finishes or the Promise is fulfilled, control is returned back to the flow.

Flow Action Component 

Here is the simple component that we will be used as flow action.

Controller 

When a component is executed as a flow local action, the flow calls the invoke method in the client-side controller. To run the code asynchronously in your client-side controller, such as when you’re making an XML HTTP request (XHR), return a Promise. When the method finishes or the Promise is fulfilled, control is returned back to the flow. When a Promise is resolved, the next element in the flow is executed. When a Promise is rejected or hits the timeout, the flow takes the Local Action element’s fault connector and sets $Flow.FaultMessage to the error message. By default, the error message is “An error occurred when the elementName element tried to execute the c:FlowAction component.” To customize the error message in $Flow.FaultMessage, return it as a new Error object in the reject() call. When a Promise is fulfilled, the next element in the flow is executed. When a Promise is rejected or times out, the flow takes the Local Action element’s fault connector and sets $Flow.FaultMessage to the error message. By default, the error message is “An error occurred when the flow tried to execute the c:FlowAction component.”. To customize the error message, return it as an error in the reject() call.

Configure the designer 

To make an attribute’s value customizable in the Cloud Flow Designer, add it to the component’s design resource. That way, flow admins can pass values between that attribute and the flow when they configure the Local Action element. That way, flow admins can pass values between that attribute and the flow when they configure the corresponding Local Action element.

Invoke Action from the Flow 

Now go to the cloud flow designer and create a new screen element to enter the country name

Add the Flow locale actions into the screen and configure the input params as shown below.

Create a screen element to show the output response as shown below.
Final screen flow looks like below

Testing 

Synchronous Code

the example code we have seen so far is Asynchronous Code where we will get the promise and here is the synchronous version of the controller.js