How To Retain Flow Variable Values Navigating To The Previous Screen?



In this post, we will talk about a workaround for one of the salesforce limitation in Screen Flow which is here. In the resolution, you can refer to the first point shared in the above article.
I will try to illustrate precisely, so please do scan that point before you proceed further.

Requirement Overview

  • Design a Screen flow with some input fields on Screen1 and assign value to a variable based on the inputs on the screen1. It could be any data type.
  • Navigate to the next Screen2 and click the “Previous” button to return to the first screen.
  • You will notice that the variable loses its value assigned to it via the input screen where it might happen that the input screen still retains those values.

Solution Approach

You can solve this limitation using a screen flow where you will be designing two subsequent screens.

Assignment Element is used to satisfy the requirement.

A Lightning web component is primarily used for navigating between the screen.

The Screen Flow footer is disabled.

The navigation buttons provided by the Lightning web component track the back button click event.

Review the Advance option used for the back button variable. (varBackClicked).

Demo

Attached screenshot will provide you a fair understanding of the implementation.

Flow Design
First Screen
Second Screen
Back button clicked from second screen

Sample Code

flowNavigation.js
flowNavigation.html
flowNavigation.js-meta.xml

For raw code , go to the git repo here

Conclusion

Imposing the assignment element between screens helps in retaining the values whereas the back button present in the lightning web component tracks the navigation.

Hope you find this post useful! Catch you in next content.
And thank you for being an awesome reader.
Share and grow together !!

If you have any doubts you can comment down below, I will try to reply ASAP.

Also keep visiting us, for more such content!

Adil Ansari

Md.Adil is a Senior Salesforce developer, a Computer Science graduate working on the Salesforce platform and providing customer solutions using force.com as a Salesforce consultant/developer. He is the founder of SalesforceBitsandBytes blogging site. He shares unique real time posts on different Salesforce implementations, the source code available on this SalesforceBitsandBytes blog is fully tested in the development environment.

One thought on “How To Retain Flow Variable Values Navigating To The Previous Screen?

  1. Hello there, just became alert to your blog through Google, and found that it’s really informative.
    I’m gonna watch out for brussels. I will appreciate if you continue this in future.
    A lot of people will be benefited from your writing.
    Cheers!

Leave a Reply

Your email address will not be published.