List views are dynamic lists that display records that meet a specific criteria. They make it possible to see all the relevant data in one place. There are many things that you can do using list views. You can add a chart to visualize the data, inline edit the records, delete records, etc. However, in order to delete a record, you should click the small arrow and then click the delete button. There is no standard button to delete multiple records at once. What if you have many records to delete?
In order to achieve this, it is possible to build a flow and create a custom button that calls it from a list view. After selecting multiple records and clicking this button, flow will run for the selected records and perform the actions. In this use case, it will delete the selected records. Read this post to learn more about passing multiple records to flow.
Let’s create a flow that deletes the selected Case records from a list view.
Screen Flow That Deletes the Selected Case Records
In this example, let’s build a flow that deletes the selected records and displays messages to the user. Since the flow will display a message, it must be a screen flow. However, if you don’t want to display anything to the user, it is possible to build an autolaunched flow too.
1- After creating the flow, create an input text collection variable called ids. If you create a text collection variable called “ids” and mark it as input variable, Id values of the selected records will be automatically passed with the custom button.
2- Create a number variable called RecordCount. Then add an Assignment element and assign the item count of the ids collection to the RecordCount variable.
3- Add a Decision element to check the selected record count. If the user didn’t select any records, you can display a message and exit the flow. If the RecordCount is greater than 0, continue with the next element.
4- Add a Delete Records element to delete the Case records that their Ids are in the ids text collection.
As you can see from this post, there are multiple ways to delete records from a list view. Using the In operator, which was introduced in the Winter ’23 release, there is no need to loop through the ids collection anymore. Therefore, this is the most efficient way and the flow performs much better than the other options.
5- Add screens for the error and success messages.
At the end, your flow should look like this.
Create a Button to Call the Flow
The flow is ready, let’s create a button that launches the flow.
Go to Case in Object Manager, click on Buttons, Links, and Actions and then click on New Button or Link.
Give it a name, select List Button and mark the checkbox called Display Checkboxes (for Multi-Record Selection). This will make the button available for list views (for the selected object only) and it will allow you select multiple records. Select Display in existing window without sidebar and header as the behavior and make sure that content source is URL. For the URL value, you have to put the flow’s URL.
You can find the URL of the flow from the flow detail page in setup. Since you created an input text collection called “ids”, it will automatically pass the Ids of the selected records.
In order to return to a page at the end of the flow, you have to add a retURL parameter to the end of the URL. Using the retURL=500/o parameter, the flow will navigate back to the Case home page (Case list view). 500 is the prefix of the Case object. If you are building the flow for another object, replace this value with the prefix of it.
Add the Button to List Views
After creating the button, add it to list views. In order to add the button, go to List View Button Layout and then click edit on List View.
Pay attention that once you add a button to list views, it will be visible on all list views of this object.
This is the end of the flow and the configurations, now it is the time to test it.