Pages

Wednesday, March 21, 2018

Salesforce: Call Flow from Action

If you check this blog again Global Actions in Lightning, Action Tyle = Flow only available in Object-Specific action, and not in Global Action. In this blog, we will share how to call Flow from an action, but will not share the basic on how to create action or how to create flow.

Use case: to increase efficiency, business users of Universal Container request the ability to update Number of Employee of Account directly from Opportunity screen.

Solution: create a flow and call it from Action.


1. Create Flow
Make sure the flow must be active and have screens, so it can't be Autolaunched Flow. Flow actions let you pass the value of the record's ID field into the flow, but that's it. Your flow needs to have a variable with Text Input called recordId, the action passes the record's ID into that variable at runtime.

see all items in Explorer panel

1st box - to get Account Id. Remember this Flow will be located in Opportunity so the variable "recordId" will return would be Opportunity Id, not Account Id. In short, this box is to query Account Id from Opportunity object.

2nd box - to get Account Name and Number of Employee. Use Account Id return from 1st query to retrieve Account Name and Number of Employee from Account object.

3rd box - in this box, the user will enter Number of Employees to update into Account, but to make it nicer, we can display Opportunity Id, Account Id, Account Name, and pre-populate Number of Employee in the textbox for user to update.

4th box - this box will save Number of Employee from screen to Account object.


2. Create Action
Create new Action with Action Type = Flow.
Select the Flow created in step 1.
Add the action to "Salesforce Mobile and Lightning Experience Actions" panel in Opportunity Page Layout, in Lightning this action will become a button, while in Salesforce mobile app it will become an icon in action bars.



3. Showtime
Now open an opportunity, you should notice a button called "Update Acct Employee".
Click the button, it will show Account Id, Opportunity Id, Account Name and pre-populate existing Number of Employee from Account.

Lightning Experience

Salesforce mobile app


I am not sure if this is a good use case because you can get something almost similar using action type "Update a Record", check this blog Update Parent Record with Action, but if your screen have logics that need query, or with multiple screens, a single "Update a Record" action will not able to  handle it, calling a Flow from an action would be a better options.


Reference:
- Update Parent Record with Action
- Global Actions in Lightning
- Flow Action Considerations
- Launch a Flow from an Object-Specific Action



No comments:

Post a Comment