Using Flow to Refresh Page Data

Using Flow to Refresh Page Data

There are many use cases where we put screen flows on record pages to guide users through business processes. Depending on the requirements, these screen flows may have multiple screens. Moreover, at different stages, they may perform updates to the open record or to records in related lists on the current page. The issue is that the page does not reflect the new updates immediately, but only when the flow finishes. Another issue is with screen flows that end with a screen that has no finish button. In this case, the page will not refresh since it never hits the "finish" point. In order to solve this issue, you can use this custom component. This component allows admins to trigger a seamless page data refresh from a flow, without having to reload the entire page. Therefore you won't lose your progress in the flow, and still see the updated data on the page.

Components of the Package

This package includes 2 different components that can be used to refresh the page data. The first one is a local action that is available in screen flows. The second one is a Lightning Web Component (LWC) that you have to put on a page. This LWC listens for a platform event that you can publish when you need the data refresh.

How to Use the Local Action

This method is pretty straightforward. Simply add the "Refresh Page Data" local action to your screen flow, and no additional configuration is required. Note that this method works for screen flows only.

Refresh Page Data - Local Action

How to Use the Lightning Web Component

This method works for all flow types (except before-save flows, since they do not support the "Create Records" element). Moreover, it even works with Apex (later on about that).

First of all, add the "Platform Event Refresh Page Data" component to the Lightning Record Page. This component will allow you to trigger a data refresh whenever you publish a "Refresh Page Data" platform event.

Platform Event Refresh Page Data

To publish a platform event from flow, use the create records element and create a "Refresh Page Data" record. Set the RecordId__c field to the Id of the relevant record that you want to refresh. The refresh will happen for the running user only, and not for the other users. Once you have set up the flow, page data will refresh automatically whenever you publish a platform event.

Publish a Platform Event to Refresh Page Data

If you want to use an Apex code instead of a flow, here is how you can publish the platform event.

Refresh_Page_Data__e refreshEvent = new Refresh_Page_Data__e(RecordId__c = '<record_id>');
EventBus.publish(refreshEvent);

Replace <record_id> with the id of the record that you want to refresh.

Example

In this example, whenever you change the opportunity stage to Closed Won, the system makes an asynchronous callout. It is possible to see the status of the interface from a field called SBO Quote Sync Status. However, since it is asynchronous, it is not possible to see the updated value without refreshing the page.

By publishing a platform event (and using the LWC on the record page), it is possible to refresh the page data. See how SBO Quote Sync Status field changes.

Refresh Page Data Example

Important Notes

Although the second method will work also for screen flows, it is better to use the local action when using a screen flow for a number of reasons.

  • It does not consume from the platform events limit (read more about platform event limits here).
  • It does not require adding an additional component to the lightning page.
  • Although platform events are usually published and received very quickly, this method is still faster.

It is recommended to add the component at the very top of the page. This way you can ensure the component is not lazy-loaded as the user scrolls through the page.

Considerations

  • There is a limit to the number of platform events one can publish and subscribe to. It depends on the Salesforce edition, and on the existence of an add-on license.
  • If the limit is reached, the page will not refresh anymore when you publish a platform event.
  • The platform event-driven component does not support mobile devices, since the empAPI library is not supported on mobile, and there isn't a known alternative.

Installation Links

Links of the package that contains both of the components:

Use this link to install in production or developer edition environments.

Use this link to install in sandbox environments.

Links of the package that contains only the Refresh Page Data action (for screen flow):

Use this link to install in production or developer edition environments.

Use this link to install in sandbox environments.

20 Comments

  1. It unfortunately does not work for me. Would you be able to post a screenshot of the flow setup itself with all its elements please?

  2. This also did not work for me using the Sandbox version. Added this to an existing, working auto-launched flow from a Button.

    • Hi Jessica,
      There are 2 components in this package.
      One of them is a local action, therefore it is available only in screen flows.
      Second one is a LWC that you need to put on the lightning page. It refreshes the page data when a platform event is received.
      Which one did you use?

  3. Hi Joshua, I'd love to try the refresh page component for the screen flow as an action but I can't get your link to open. I've tried in Chrome and Safari, any suggestions please? Thanks

  4. When I click on the link nothing happens, if I paste it in to a new tab it just spins on the tab and nothing loads. This is the same in Safari or Chrome. I don't get to the point of installation.

  5. I'm using the platform event method from a screen flow, it updates the lighting page for the user who ran the flow. But, other users pages don't refresh. I've confirmed all users have permission to create and read the event. Any suggestions?

    • Hey Dan,

      This component is designed to refresh the page for the current user only and not for the other users.
      Otherwise, if another user is in the middle of editing the record, their changes might be overwritten.

  6. Getting the following error when using the local action method at the end of a screen flow in a sandbox (the screen flow is launched from a custom URL button):
    Action failed: c:refreshPageData$controller$invoke [Cannot read properties of undefined (reading 'fire')]

    • Hey Juan,

      The local action component is suppose to be used in a screen flow that is either embedded on a lightning page or opened from a quick action.
      The data that should be refreshed in that case is the open record and it's related lists etc.
      But, when opening from a URL button there is no open record. So, what data are you trying to refresh?

      • Hi Joshua,

        Thanks for the quick response! I had to use a custom URL button to launch the flow because I needed to launch the flow from a related list button and a custom URL button is the only way to do that (as far as I can tell). What I was ultimately trying to refresh was an opportunity record page.

        I've found a workaround in the meantime, thankfully!

1 Trackback / Pingback

  1. Refresh Record Page Data Using a Quick Action - Salesforce Time

Leave a Reply

Your email address will not be published.


*