Control finish behavior for URL launched flows
Last week I did an article on how to mass update records from list views using flows. And I got a lot of comments related about how we can redirect the flow when it’s finished. One of the most asked was how can we redirect back to the list view from where the flow was invoked. And just when I was about to give up finding a solution, one of our fellow trailblazer ‘jele'(name that shows up in the comments 😅) helped me out. It’s an interesting solution, which I had used in the past at many places but it never occurred to me that I’d use it in Lightning.
So let’s start with how you can redirect a flow when it finishes.
Using retURL url parameter
Syntax: /flow/FlowApiName?retURL=<URL>
For example, if you want the flow to redirect back to the Opportunity page from where it was triggered then it’d look something like this:
/flow/FlowApiName?retURL=/{!Opportunity.Id}
Now let’s just discuss what you’re really here for!
Redirecting back to the list view
To solve this piece, we need a Visualforce page, back to good(debatable) old Salesforce Classic days. Don’t worry! It’s very simple, just 2 lines of code. 🙂 And you’d need one vf page for each object where you want to redirect back to list view.
Let’s take an example of Account object. Say, we have a list button for Account list views that invokes a flow.
Step 1: Create a vf page, say AccountRecentListView, like this:
<apex:page standardController="Account" recordSetVar="recordsList" action="{!list}"> </apex:page>
Step 2: Set the retURL parameter to navigate to the vf page we created.
/flow/FlowApiName?retURL=/apex/AccountRecentListView
Save, and that’s it!! You can reuse this vf page anywhere to redirect back to the your last viewed Account list view.
Important NOTE: Make sure to set the ‘Behavior’ of your list button as “Display in existing window without sidebar or header“, or else, redirection doesn’t work.
I hope you find this useful! I’ll catch you in the next one! ✌ Thank you for being an awesome reader! Subscribe to ForcePanda to receive all the latest updates straight to your inbox. 🙂

.png)




Comments