Refresh your visual flow in lightning when record is updated
Problem statement —
Refresh the flow when record is updated in the detail page
You have your plain old lightning flow that displays a field onto it
eg. a flow conatins Account name (I know its redundant but there are some scenarios where some users don’t like info in the record detail section and want to see it in the adjacent accordian… hence flows!!!)
Now every thing is cool and all until the user updates the account name in the record page and expects it to refresh it in the flow as well, but that does’t happen in the flow. You have to refresh the entire page to make that happen.
But who likes refreshing a heavy salesforce page — Yuckkk!!!!
The main reason why flow fails here is — when a record page is updated, they send out a force:event accross the page and expect others to catch it.
But poor flow doesn’t do that.
So lets see how we can catch the page event tell the flow — “Dude its time to refresh…”
Lightning Aura components make it easy to catch such page events.
So overview of what we are gonna do is —
1. Create an Aura component that embeds our flow.
2. Whenever the record is updated, catch the event and refresh the flow.
But the problem with refreshing a embedded lightning:flow is that you can’t do that.
So change of plans
1. Create an Aura component that embeds our flow.
2. Whenever the record is updated, catch the event and remove the <lightning:flow> tag entirely and dynamically create a <lightning:flow> tag in the component to launch the flow
But hold it!!!!
This is also not possible because you cannot create dynamic <lightning:flow> tag.
Boy this is getting tough…
There’s a workaround to this, and you’ll understand why you cannot find this solution on other sites.
1. Create an Aura component that embeds another Aura component (because you can dynamically refresh aura components)
2. This new Child Aura component has our flow embedded in it.
3. Whenever the record is updated, catch the event and remove the child aura component and replace it entirely with same but new child component