top of page

Salesforce Hacks # 6 : ( Hard ) Refresh the page after screen flow completes

caleksiev

Ok, this is one was really interesting to build! SCENARIO:


I have a parent record, in my case Contract and related list, Orders for me. I want to have a related list button that executes a screen flow, mass update the related records, in my scenario marks / unmarks a checkbox and returns to the parent record after my flow finishes.


THE PROBLEM:


Everything is working great, BUT after my flow finishes, the updates I made to the children records in the related list weren't there.... or they are, but I have to do a ( hard CtrL + Shift + R for Win ) refresh of the page in order to view my updates.... Not cool at all!


NORMAL SOLUTION:


If you face this issue, there are 2 possible solutions for you:

- create a component of your own that does the refresh for you. You can find discussions about this approach here for example https://salesforce.stackexchange.com/questions/301086/refresh-the-page-after-the-flow-completes/361423#361423;


- use https://unofficialsf.com/update-screen/ component. Hats off for this website, if you don't know it / use it, you should DEFINETELY start doing so;


FYI: this article that Yumi Ibrahimzade ( https://www.linkedin.com/in/yumiibrahimzade/ ) wrote is also amazing and it's worth checking it out, if you have to do something like this https://salesforcetime.com/2023/03/21/a-flow-action-to-refresh-the-page/ Keep in mind that Yumi is truly amazing in finding flow solutions, again put his website in your favorites!


THE SALESFORCE HACK WAY:

Now, the fun begins! The above mentioned articles work and I highly recommend to check them out if you haven't already, but I wanted to figure out a way without the need of installing components ( or writing those ).


So, to begin with, "How to start a flow from a custom button on a related list?"


Start creating a Screen flow, add a New Resource -> variable, like this:

VERY IMPORTANT:

- the name of the variable is case sensitive and it should be "ids" exactly!!!


- Data Type: Text ( we are passing the selected Ids here )


- Allow multiple values (collection)


- Available for input


Another resource -> variable, like this:

VERY IMPORTANT:

- the name of the variable is case sensitive and it should be "recordId" exactly!!!


- Data Type: here you can choose either Record or Text. If you choose text and you need some data from the record itself ( the parent record in our case ), you will need an additional Get element inside the flow. If you choose the Record data type, you will get passed the whole record with all it's data and no Get element is needed, depending on your needs.


- Available for input


How to check if any records are selected from the related list before clicking the button? Easy, use the assignment element in the beginning of the flow and check the size of the collection variable "ids":

Now, use a Decision element to check if the size variable is greater than 0


If yes, continue with your logic, if not - show a finish screen with a nice message like "No records have been selected! Please, go back and select records from the Orders related list!"


Ok, now moving forward: get the child elements that have been selected: The filter is simple, select all Order records, which Id is IN ( being contained ) the ids collection

Use a Loop element to iterate the children records and an assignment element to set the new value that you want. In my case, set a particular checkbox to TRUE, so

Current Item from Loop name EQUALS TRUE


Use another assignment element to add the current iterations record, with the newly assigned value, to a new collection for the update.


Both of these assignments can be done in a single assignment element, but it's a good idea to keep them separate for readability reasons, but you can do it like this:

Update element to make the DML on the "COLL_Selected_Orders_For_Update" and now...


Add a new Text Template variable, let's call it "TEXT_Finish_Button" and add ( are you ready ) HTML tag with CSS class in it, like this:

Before start reacting like "WHAAAAAAAAT?! This is not possible!!!", READ this amazing article from ( surprise, surprise ) unofficialsf

https://unofficialsf.com/build-lightning-styled-screen-flows-that-users-will-love/ Anchor tag ( the <a></a> ) is a standard HTML tag, in our case using the SLDS system ( the class property ) and the href property is the link for the redirect aka

/lightning/r/Contract/{!Contract.Id}/view

Update the Contract with the object you want and the {!Contract.Id} as well


Ok, let's finish our flow, add the finish screen and add a display text in it, using the text template variable we just created, like this:



Now, on the Finish screen, remove the mark on the "Show Footer" checkbox so that we are sure that the standard Finish button is not going to show up.


Keep in mind that saving a screen flow without the footer ( no finish or back button ) will alert you with a warning, but this will not stop you from activating it or using it!

Save the flow, give it a nice name and head to your child object, in my case, the Order.

Click "Buttons, Links, and Actions" and create your new button:


Use the "List Button" radio option, mark the "Display Checkboxes (for Multi-Record Selection)" checkbox.

Behavior "Display in existing window without sidebar or header".


Add the link to your flow ( use the name of your flow ):

/flow/My_Super_Cool_Related_List_Screen_Flow?recordId={!Contract.Id}&retURL=/lightning/r/Contract/{!Contract.Id}/view


Let's brake it down: /flow/My_Super_Cool_Related_List_Screen_Flow - the link to your screen flow


?recordId={!Contract.Id} - the Id of the parent record, where you can find the related list and where the button will be


&retURL=/lightning/r/Contract/{!Contract.Id}/view - when the flow finishes aka the user clicks "Finish" button on the last screen from the flow, the return URL will be the parent object id where you started from. I am adding this part because of the let's call it "Fault path", where there are no records selected from the related list and in the decision we take the end screen path aka I am finishing my flow the "normal way".


NB: where to find the name of the flow you just created? Go to flows, on the line of each flow you have a dropdown:

Click "View Details and Versions"


Here you will see the API name of your flow and the URL. Copy the whole URL


Ok, now add the related list button on the parent page layout. Go to the parent object, in my case the Contract, hit Page Layouts than on the desired page layout, click Related Lists and on the desired related list, next to the name, you have a small Rench icon

On the new screen, at the bottom, you will see the + for the Buttons

You should be able to see your new button in the "Available Buttons" - select it and move it to the "Selected Buttons" and Save the changes.


NB: if you are not able to see any buttons on the related list, while still on the parent record page, click Setup than Edit Page

Click on the related section and check if marking this checkbox does the trick for you "Show list view action bar":

Save the changes and go to verify the work you have done :)

Hah! Seems like a real Finish button to me! AND it actually reloads the page and you are able to see the updates that you have made on the related records!


Have fun and I hope this helps!




2,758 views0 comments

Recent Posts

See All

Comments


Proudly created with Wix.com

bottom of page