Using Flow Builder to Update Selected List View Records
Did you ever wonder how you can declaratively pass the IDs of selected records to Flow Builder from a list view?
Well, this article may be what you are looking for!
Join Chuck Morris, a Salesforce Admin who works at KarateKit.COM, who has just created this process without coding.
Chuck has recently received a new requirement: Lightning Experience Users want to be able to close one or more Case records by selecting these records within a list view.
In order to make it happen, Chuck needed to find a solution. Initially, he was about to ask his developer to develop it. A moment before he made the call, he remembered a line he had heard many times before: "Use the force wisely, Chuck...".
After sleeping on the requirement, he came up with a solution. His solution is based on Flow Builder and a Flow Action called 'Get/Search with APEX' created by GravityLab.
> Make sure you install the Flow Action before you start building the process (Sandbox | Production)
Update (JUL.08.20): Following a suggestion I've received, there is no need for the Apex Action. Please review the full explanation at the end of the article. The changes I've made are relevant to both the Loop and the Assignment Elements.
1. Creating a Flow
In Lightning, go to Setup | Process Automation | Flows
A. Creating a new Flow
- In the Flows page, click on the 'New Flow' button.
2. In the new window, select 'Autolaunched Flow'.
3. Click on the 'Create' button.
B. Defining the Flow Trigger
Double click on the 'Start' element and define as follows:
- Under the 'What Launches the Flow' option, select 'Users of apps-no flow trigger'.
- When you're finished, click 'Done'
C. Create the following variables:
Collection Variable:
- ids - a Text Collection that will hold the selected Case record IDs. Note that the IDs will be automatically passed to the Flow. No additional steps are required.
Record (Single) Variable:
- SO_Cases - a record variable for each of the Case records
Record Collection Variables
- SOC_Cases - the Collection is used for updating the Case records
- SOC_CaseCollectionOutput - a record collection variable to hold the case records that will be retrieved by an Apex Action.
D. Adding an Apex Action
Drag the 'Action' element to the canvas and define the following information:
Under the 'Set Input Values', define the following information:
> In this section, we've defined the action to return the Case Id and the Status of each record. Under the 'List Of Ids' we have added the 'ids' collection variable.
Under the 'Store Output Values', define the following information:
> Make sure you select the 'Manually assign variables (advanced)' and add the 'SOC_CaseCollectionOutput' record collection variable under the 'outputCollection'.
Now you can connect the Start element to the Action element you just created:
> Make sure you save your flow.
E. Creating a Loop element
Drag the 'Loop' element to the canvas and provide it with the following information:
When you're finished, click 'Done'.
Connect the Action element to the Loop element you just created and click 'Done':
F. Creating an Assignment element
Drag an 'Assignment' element to the canvas and provide it with the following information:
When you're finished, click 'Done'.
Connect the Loop element to the Assignment element you just created and click on the 'Done' button in the new screen that will appear:
The flow will look as follows:
G. Creating a second Assignment Element
Drag another 'Assignment' element to the canvas and provide it with the following information:
When you're finished, click on 'Done'.
Connect the first Assignment element to the Assignment element you just created, and then connect the second Assignment element back to the Loop element:
> Make sure you save your flow occasionally. Just in case...
H. Creating an Update Records Element
Drag the 'Update Records' element to the canvas and provide it with the following information:
When you're finished, click 'Done'.
Connect the Loop element to the Update Records element you just created - The Flow is ready:
> Make sure you click on the 'Save' button BEFORE activating the flow.
I. Activating the Flow
After saving the flow, click on the 'Activate' button located at the top-right side of the screen:
2. Creating a Custom Button
In Lightning, go to Setup | Objects and Fields | Object Manager
In the Object Manager, search for the Case object and select it.
A. Creating a List Button
In the left pane, click on 'Buttons, Links, and Actions' (A). Then, click on the 'New Button or Link' button located to the right (B).
B. Defining the List Button
- Provide the button with a meaningful name and a description.
- Under the 'Display Type', select 'List Button'.
- Under the 'Behavior', select 'Display in existing window without sidebar or header'
- Under the 'Content Source', select 'URL'
- In the large text box, paste the following URL (You'll have to change the List View Id to your own Id):
/flow/Closing_Cases_from_Related_List_of_List_Views_Flow?retURL=/lightning/o/Case/list?filterName=00B0Y000002xMTkUAM
6. When you're finished, click 'Done'
Let's break that down:
- The following URL defines to which flow we are calling
/flow/Closing_Cases_from_Related_List_of_List_Views_Flow
You can copy the flow’s URL from the Flow Detail page:
- After the question mark, add the following URL.
retURL=/lightning/o/Case/list?filterName=00B0Y000002xMTkUAM
This will define the Salesforce page our users will be redirected once the update is finished. In our demonstration, we are redirecting them to a specific Case List View (again, use your own list view Id).
3. Adding the Custom Button to the Search Layout
In Lightning, go to Setup | Objects and Fields | Object Manager
In the Object Manager, search for the Case object and select it.
A. Selecting the Search Layout
In the left pane, click on 'Search Layouts for Salesforce Classic'. Yes, I know it might be strange that I didn't choose the 'Search Layouts' option. For some reason, the custom button appeared in my list view only when I added it to the Salesforce Classic search layout. If you know the reason why, please let me know, I will be more than happy to update my article.
B. Adding the Custom Button to the List View layout
Drag the 'Close Cases' custom button from the 'Available Buttons' to the 'Selected Buttons' and click 'Save'.
The button is now added to the list view:
Update (JUL.08.2020):
Following a suggestion I've received from Alex Rabinovich I was able to create the process without the Apex Action. Alex suggested adding the 'ids' record collection variable into the loop under the 'Collection Variable' and then to add a (single) variable under the 'Loop Variable'.
This is how the Loop element would look like:
Now, update the Assignment element as follows:
That's it - everything else stays the same.
This is why I love the Salesforce platform so much - every day I can learn something new :)
The process is ready!
Watch the process in action:
A few important notes:
- Note that the 'ids' variable isn't documented in Salesforce documentation, so please use it in your own discretion.
- This process can also be used with Enhanced Lists!
- Note that starting Summer '20 release the Loop Variable is automatically created.
- Make sure you test the process in your sandbox environment before deploying it to your production environment.
- There are several ways to perform this business scenario, so make sure your solution is based on your business requirements and the tools that are available to you as for now.
If it’s not Virtual Worlds - It’s still not VR!
3 å¹´Tried this on a Contact list view. I couldn't get the selected list through to the flow despite trying the 'ids' tip. I used a visual force page as described by Vibhor at https://www.accidentalcodersf.com/2020/07/use-flows-from-list-views-salesforce.html
Salesforce Architect at IBM
3 å¹´Gidi, Do you have the complete example for same use case without using Apex action?
Salesforce Developer || 3X Salesforce Certified
3 å¹´is there any way to pass ListViewId dynamically to retURL?
?? 5x Salesforce Certified | External Consultant at CyberArk
4 å¹´Genius, Its exactly what i was looking for for a issue that i have
Salesforce Administrator | Project Manager | Revenue and Volume Operations Analyst | Salesforce Manager | Business Analyst
4 å¹´Hi Gidi Abramovich Is it possible with Flow Builder to update an object record using data from reports?