Hey learners, in the dynamic world of Salesforce, efficiency, and automation are key. Salesforce Administrators and Developers constantly seek solutions to optimize processes and enhance user experience. One such powerful feature is the ability to perform mass actions directly from the List View using Flow. After learning this, you could use the logic to perform your customized mass action.
Traditionally, performing actions on multiple records in Salesforce required navigating through each record individually or using Apex code for bulk operations. This was time-consuming and inefficient. With Flow, you can now execute actions on multiple records selected from a ListView, streamlining operations and saving precious time. Today, I will help you to learn how to use flow to perform mass actions such as updating, deleting the records, or emailing contacts from the list view of an object. Here I will be using a flow to delete the records selected in the list view.
Use Case Examples
Bulk Updating Records: Suppose you have a list of cases that need their status updated to 'Closed '. With a Flow, you can select all these records from the List View and update them in one go.
Mass Emailing: Need to send an email to multiple contacts? Select them from the List View and trigger a Flow to send a customized email to each contact.
Data Cleaning: Easily delete or modify records in bulk to maintain data quality and integrity.
Today I will be sharing the knowledge of flow to mass delete the records from the list view.
Check out the list of functionalities we are going to develop.
● Creation of a Delete Records button in the list view to perform mass deletion from the list view for the end users.
● Creation of screen flow having the following functionalities:
A checkpoint to ensure whether the user is confirmed to delete the records.
Display the number of successful and unsuccessful, total records checked for deletions.
Display the error messages leading to the prevention of deletion of the records.
Notify the Admin of unsuccessful deletions. (By default functionality provided by Salesforce).
What will we achieve in the end?
Step 1: Create a new screen flow.
Go to Setup. >> search flows >> create new screen flow.
Create a variable of type list to store the list of IDs from the list view.
Create a Confirmation Screen.
○ Add a screen element: Confirmation Screen
○ Add a display text element: Confirmation
i. Add the following text
Are you sure you want to delete these records?
If not, select No from the dropdown.
If records are deleted mistakenly, contact your administrator to restore the records.
Now we will create a picklist for confirmation.
i. Drag and drop the Picklist component
1. Give the name: Please select an option
2. Check the required checkbox.
3. Select No on Let Users Select Multiple Options.
4. Add choices
a. Create new choice resources: Yes
b. Create new choice resources: No
ii. Configure screen properties
1. Configure header >> Uncheck Show Header
2. Configure footer >> Show footer
3. Next or Finish Button >> Use a custom label: Proceed
4. Previous Button >> Use a custom label: Cancel
5. Pause Button >> Hide Pause
iii. Click on Done.
Now we will create a picklist for confirmation.
i. Drag and drop the Picklist component
1. Give the name: Please select an option
2. Check the required checkbox.
3. Select No on Let Users Select Multiple Options.
4. Add choices
a. Create new choice resources: Yes
b. Create new choice resources: No
ii. Configure screen properties
1. Configure header >> Uncheck Show Header
2. Configure footer >> Show footer
3. Next or Finish Button >> Use a custom label: Proceed
4. Previous Button >> Use a custom label: Cancel
5. Pause Button >> Hide Pause
iii. Click on Done.
3. Create a Decision element: Delete Records?
1. Outcome Label: Proceed
a. Select: All Conditions are Met
b. Click Done.
Now to track how many records were selected and no. of records that succeeded and failed to be deleted we will have to make a loop that would iterate over the ids variable that we made in step 1.1.
Create a Loop element: iterate over ids.
Create a Delete records element:
○ Object>> Account
○ Conditions are met >> Id Equals Current value from loop (Step 1.4).
Create an Assignment>> Successful Deletions
○ Create a new resource>> Type: Variable, API name: SuccessRecordCount, Data-type: Number, Decimal: 0, Default: 0
○ Set variable value: SuccessRecordCount Add 1
○ Attach after delete records.
○ Click Done.
Create an Assignment>> Failed Deletions
○ Create new resources>>
i. Type: Variable, API name: failedRecordsCount, Data-type: Number, Decimal: 0, Default: 0
ii. Type: Variable, API name: TotalRecordsSelected, Data-type: Number, Decimal: 0, Default: 0
iii. Type: Variable, API name: Error_Messages, Data-type: Text
iv. Type: Formula, API name: formatted_Error_Details, Data-type: TextFormula:
SUBSTITUTE(LEFT({!$Flow.FaultMessage}, FIND( ". You can look up ExceptionCode", {!$Flow.FaultMessage})-1), "The flow tried to delete these records:", "")
Aim: The Flow.FaultMessage in the above function contains the error message of the operation, we are using the above substitute for the following lines by “ ” because these were not user-friendly.
1. The flow tried to delete these records:
2. You can look up the ExceptionCodes in the SOAP API Developer Guide.
v. Type: Formula, API name: new_Line, Data-type: Text, Formula: BR()Aim: To add the new line in between the new fault messages.
Set variable values >> Reference:
○ Attach to delete records - Fault Path and loop.
○ Click Done.
Create an Assignment>> Total Count
○ Add failedRecordsCount to TotalRecordsSelected.
○ Add SuccessRecordCount to TotalRecordsSelected.
Create a screen>> Deletion Results
○ Create a display text>> TotalCounts Value: {!TotalRecordsSelected} account records were selected for deletion.
○ Create a display text>> Total_SuccessValue: {!SuccessRecordCount} Records Deleted Successfully.
Set Component Visibility: SuccessRecordCount Greater Than 0
○ Create a display text>> Deletion_ProblemsValue: {!failedRecordsCount} records could not be deleted. Report your System Administrator these details :
{!Error_Messages}
Set Component Visibility: failedRecordsCount Greater Than 0
○ Configure Header>> Uncheck Show Header
○ Configure Footer>>
i. Check Show Header
ii. Hide Previous
iii. Hide Pause
○ Click Done.
Give the flow your_flow_API_Name.>> Save >> Activate
Step 2: Add the Button to the Account List View
Go to setup. >> Object Manager >> Account
Go to the Buttons, Links, and Actions >> Create a new button >>
Label: Delete Records
Display Type: List Buttons
Behavior: Display in existing window without sidebar or header
Content Source : URL : /flow/your_flow_API_Name?retURL=/001
Save
Go to List View Button Layouts >> Edit List View
Add Mass Delete Button from Custom Button to Standard Buttons box.
b. Save
Conclusion
Leveraging Flow we can also perform mass action from list view. It brings about a myriad of advantages that contribute to increased efficiency, improved data accuracy, and overall productivity allowing for the automation of complex processes, reducing manual intervention, and minimizing the risk of errors.
The User-friendly and visually intuitive nature of Flow empowers users across various skill levels to create and modify processes without extensive coding knowledge.
References
https://help.salesforce.com/s/articleView?id=sf.flow_actions_considerations.htm&type=5
https://help.salesforce.com/s/articleView?id=sf.flow_ref.htm&type=5
https://help.salesforce.com/s/articleView?id=sf.flow_concepts_bulkification.htm&type=5
https://help.salesforce.com/s/articleView?id=ind.comms_t_bulk_operations_232824.htm&type=5
https://help.salesforce.com/s/articleView?id=sf.mass_quick_actions_create.htm&type=5
https://help.salesforce.com/s/articleView?id=000386168&type=1
If you'd like to see the code and resources used in this project, you can access the repository on GitHub.To access the AVENOIRBLOGS repository, click here. Feel free to explore the code and use it as a reference for your projects.
Thank You! You can leave a comment to help me understand how the blog helped you. If you need further assistance, please contact us. You can click "Reach Us" on the website and share the issue with me.
Blog Credit:
D. Dewangan
Salesforce Developer
Avenoir Technologies Pvt. Ltd.
Reach us: team@avenoir.ai
Are you in need of Salesforce Developers?
Reach Us Now!