Hi, there! 🙋♂️
Launching flows via URL is generally not preferred mostly because of all the limitations associated with for example, unpleasant UI, requires enabling Lightning runtime, redirection limitations, limited(almost none) usability of custom lightning flow actions etc.
Note: Enabling Lightning runtime doesn’t change the context(or host) to lightning. AFAIK, there is no official doc to explain this.
Meet ‘URL Flow Launcher’ Component
Simply put, this component allows to call any flow via URL.
How it works is, the URL calls the component and the component calls the flow. And you’ll also be able to pass parameters to the flow by specifying them in the URL.
How it works?
The URL to call the component is:
/lightning/cmp/c__URLFlowLauncher
?c__flowApiName=<ApiName of the Flow>
‘ c__URLFlowLauncher’ is the name of the component and c__flowApiName is the parameter which should be set with the API name of your flow.
Passing parameters
You can also values to your flow input variables from the URL itself.
For example, you have a flow where you have following input type variables: textInput(Text Type), booleanInput(Boolean type), numberInput(Number Type), dateInput(Date type), then the URL will look like this:
/lightning/cmp/c__URLFlowLauncher
?c__flowApiName=Test_Screen_Flow
&c__textInput=Astro
&c__booleanInput=true
&c__numberInput=911
&c__dateInput={!TEXT(TODAY())}
Note how every parameter is prefixed with ‘c__’. So make sure you prepend the flow variable name with ‘c__’.
Format for Date type variables: YYYY-MM-DD
Passing collections
You can pass value to text type collection flow variable as follows:
/lightning/cmp/c__URLFlowLauncher
?c__flowApiName=Test_Screen_Flow
&c__textCollection=[a,b,c]
Where ‘textCollection’ is the name of the flow collection variable and “a, b, c” are the values that we want to pass to the collection variable.
Redirection
You can set the redirection behavior of the flow as well by setting the ‘c__returnURL’ parameter. Please note, it’s NOT ‘retURL’.
Say, you want to redirect to the Account record from where the flow was invoked, then the URL would look like this:
/lightning/cmp/c__URLFlowLauncher
?c__flowApiName=Test_Screen_Flow
&c__textInput=AStro
&c__returnURL=/{!Account.Id}
What more can you do?
You can basically do everything that you can normally do in a flow. You will be able to use custom flows actions for toast event, Lightning Data Service, Navigation service etc. Checkout unofficialsf.com for all the flow actions and other flow resources.
Demo
Source Code and package link can be found here: https://github.com/forcePanda/Lightning-Components-Repo/tree/master/URL%20Flow%20Launcher
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. 🙂
Great component! Thanks
LikeLike
Thanks, Eric!
LikeLike
I am trying to use this from a button on a related list based on your excellent post on using the “ids” text collection of the selected record Ids, but I am getting the “Invalid request, post must use JSON” error message and it does not work.
LikeLike
Well, unfortunately we cannot pass ids like that from list views or related lists to lightning component. It’s a platform limitation.
I know, sucks!
LikeLike
Thank you for the quick reply.
I have the problem, that I have tried all the tricks in your posts and in some more (that were posted below your posts) and it still doesn’t work.
I have a related list (both the child and the parent are custom objects) of some records and I need to give users the ability to change one checkbox field in them directly from within the list. I can do it in one of two ways: either to create a list view button that I put on the related list and then I can pass a collection of ‘ids’ OR I could possibly create a Formula(text) field with a URL in it. In both of these cases, I would call a flow to set that checkbox/checkboxes.
All of this works just fine (thanks for the ‘ids’ solution!!), but I cannot solve the issue of returning to the record page, where the user started from. I always get the “Your flow has finished.” message and that’s it.
I have tried retURL, the flow launcher component, and the NavigateEverywhereLFA from unofficialsf.com, but nothing works. I think I must have gotten the closest when I got an error message saying something like “your browser doesn’t support cross-site cookies” or something like that.
Do you have any suggestions?
LikeLike
I think simply setting the retURL as this should work:
/flow/flowApiName?retURL=/{!ParentObject.Id}
LikeLike
Thank you so much for this!
I am only experiencing one problem. The passed variables are cached — same as described here:https://salesforce.stackexchange.com/questions/298932/lightningisurladdressable-cache-issue
And, perhaps, the solution on above page can fix but I am too inexperienced to know precisely how/where to apply the fix. I have gone so far as to open the component in developer console and copy/pasted from above article and saved. Probably I am putting it in the wrong place/syntax.
(I cannot even describe myself as a novice with lightning components–indeed, I am in over my head.)
I do expect I can get a co-worker to rescue me, but wanted to report this to you. Maybe you can send me in the right direction?
LikeLike
Can you share more about your use case?
LikeLike
Sure — This very brief video that I made for my manager reveals what I’m up to:
LikeLike
Ahh, got it! Let me try and find some time to fix the caching issue. Hopefully by this weekend!
LikeLike
Thank you and no rush! Great blog—I do appreciate.
LikeLike
I added the fix. The new package link is added in the README file on GitHub. 🙂
LikeLike
Thank you! Though it will be tomorrow before I can check it out, did not want to hesitate to acknowledge receipt of your message.
LikeLike
Follow-up: Installed and tested. It’s working perfectly. Thank you!
LikeLike
Hello!
Thanks very much for this component. I’m wondering if this component can open a screen flow as a pop up overlay? In my case I want to use this URL button in a list view, and when clicking the button I don’t want to be redirected to another page to follow the screen flow, but do it in a pop-up overlay, the same way a quick action flow button works (however, these are not available in list views).
Is this possible?
Thanks!
LikeLike
AFAIK, that’d not be possible with list views. Functionality around list view button is very limited.
LikeLike
Ok. I have just posted a question in Stackexchange regarding this where I give a bit more detail, if you could look at it and see if anything rings a bell, that would be great: https://salesforce.stackexchange.com/questions/352855/list-button-with-url-to-launch-a-flow-in-modal-pop-up-window-is-it-possible
Thanks very much,
Roberto
LikeLike
This is gold, Narender. Thank you.
LikeLike
I hope you don’t mind, but I added a link to this to the Utilities page on unofficialsf.com.
https://unofficialsf.com/lightning-apps-home/
LikeLike
Of course not! 😀
LikeLike
This is a perfect solution for getting flows running from listview buttons. Thank you!
LikeLike
Installed and run on the desktop, but it won’t work on Salesforce Mobile App (Salesforce1). Any idea why?
Thank you!
LikeLike