Launch Screen Flow from Platform Event to Targeted Users in Salesforce

Munawirrahman
7 min readOct 22, 2022

--

Hi Folks!

As a Salesforce Flow developer, you may want to enforce (or persuade) your user to see and use your beautiful Screen Flow when there’s a certain event happened in your org. What I meant by event here, it can be anything like when someone created a record, updated a record, deleted a record, a deadline is due, another system hit your Salesforce org API, etc. On this article, I would like to show you how you can configure Screen Flow launch mechanism to a targeted users and/or context when there’s an Event (or Platform Event) fired in real time.

Image00 Thumbnail

Main Features

  1. Launch a Screen Flow Modal to targeted active session user(s) and/or targeted context. Context will be decided by a unique key.
  2. Screen Flow Modal will be shown wherever the Screen Flow Platform Event Listener component is being set. For example, you put Screen Flow Platform Event Listener on Account Lightning Page, then the targeted user can see the Screen Flow on the Account Lightning Page. If you put it on Utility Bar, then your user can see the Screen Flow as long as the user has the app open.
  3. You can dynamically launch whichever screen flow based on flow api name.
  4. You can filter who should see your Screen Flow based on their user Id.
  5. You can filter whether your user should see your Screen Flow or not based on a matching unique key.
  6. You can set input variables to your flow from platform event attribute.
  7. You can set Screen flow finished behavior whether it should restart or it should close the modal.
  8. You can set the header modal label.
Image01 How it works Diagram

First, Screen Flow Event (Platform Event)

This is a prebuilt platform event that you will get once you installed the package. The utility of this platform event is to notify the Screen Flow Platform Event Listener about the what, where, and who sees the screen flow. To launch the screen flow, you need to publish this event (or Create a Screen Flow Event record) with the configured attributes. You can publish platform event from Record Triggered Flow, Autolaunched Flow, Scheduled Triggered Flow, Screen Flow, Apex, etc.
Attributes a.k.a Fields

  1. Label : Screen Flow API Name
    API Name : Screen_Flow_API_Name__c
    Type : Text (Mandatory)
    Description : A Screen Flow API name that you want to launch
    Example : Create_an_Account_Flow
  2. Label : Restart on Finish?
    API Name : Restart_on_Finish__c
    Type : Boolean (Optional)
    Description : If true, it will start a new flow interview once your Screen Flow finished.
    Example : True
  3. Label : Modal Header Label
    API Name : Modal_Header_Label__c
    Type : Text (Optional)
    Description : If being filled, the modal will have header with text that you set in this attribute. check Image02 and Image03
    Example : This is a Modal Header Label
  4. Label : Target User Ids
    API Name : Target_User_Ids__c
    Type : Long Text Area (Optional)
    Description : If being filled, the modal will only launch to user with User.Id within this attribute. The format of this attribute is comma separated. If not filled, all user with screen that listen to this event will see the screen.
    Example : 0055g0000037HFy,0055g0000031PAm,0055g0000037STa
  5. Label : Unique Key
    API Name : Unique_Key__c
    Type : Text (Optional)
    Description : If being filled, this unique key will check whether unique key on the event matched with Screen Flow Platform Event Listener’s Unique Key or not. If matched, it will launch the screen flow.
    Example : CLOSED_WON_PAGE
  6. Label : Launch when current URL contains?
    API Name : Launch_when_current_URL_contains__c
    Type : Text (Optional)
    Description : If being filled, this attribute will check whether the current URL of your browser tab contains a text in this attribute or not (utilizing window.location.href). If yes, it will launch the screen flow.
    Example : /lightning/page/home => to only launch on home page tab
  7. Label : Input Variables
    API Name : Input_Variables__c
    Type : Long Text Area (Optional)
    Description : If being filled, this will be the input variables to your screen flow. The format of this attribute is an Array of JSON. Make sure that the variable is available for Input. This attribute really prone to cause error, so please recheck your JSON format. Pro Tip : you can use text template and pass it to this attribute.
    Example :
[
{
"name":"inputText",
"type":"String",
"value":"some-id"
},
{
"name":"inputNumber",
"type":"Number",
"value":123123
},
{
"name":"inputBoolean",
"type":"Boolean",
"value":false
},
{
"name":"inputCurrency",
"type":"Currency",
"value":12312
},
{
"name":"inputDate",
"type":"Date",
"value":"2022-12-13"
},
{
"name":"inputDateTime",
"type":"DateTime",
"value":"2016-10-30T15:27:02.000Z"
}
]

I don’t really know how to pass Collection, Record, Apex-Defined kind of variables. If you know, you can let me know in the comment or refer me to a link and I will add it here. If you still couldn’t find it, maybe ask Salesforce to complete their documentation :)

Image02 Sample Screen Flow without Modal Header
Image03 Sample Screen Flow with Modal Header

Second, Screen Flow Platform Event Listener (Lightning Component)

This is a component that you need to put on your user’s lightning page. The utility of this component is to listen to events that being triggered and launch the Screen Flow modal to your user if the event triggered met criteria to launch the modal.

Screen Flow Platform Event Listener supported following lightning pages :
Record Page, App Page, Home Page, Flow Screen, and Utility Bar.

My personal preference is to put this lightning component in a screen flow. The reason is because we can embed the flow in any supported pages and we can have more control for the attributes within this component.

Attributes

  1. Label : Unique Key to Identify Event (Non User.Id)
    Type : Text (Optional)
    Description : If being filled, this unique key will check whether unique key on this component matched with event’s Unique Key or not. If matched, it will launch the screen flow.

Sample Use Case

Problem:
Anna, a Sales Manager from Sales Department is not satisfied with standard salesforce notifications and email notification every time there’s a big amount opportunity closed won, she wants to get notified immediately to congratulate the opportunity owner directly. She is okay if her work while opening Salesforce website get interrupted. She is always working on Sales App.

Design Solution:

  1. Prepare a Screen Flow to notify Anna. We will pass the Opportunity recordId to the Screen Flow and Get the Opportunity based on that recordId to show who is the Opportunity Owner. Activate it
  2. Create a record triggered Flow with big amount (more than or equal to 1 mio usd) and Closed Won as criteria, and Create a Screen Flow Event to notify Anna. Activate it.
  3. Since Anna mostly working in Sales App, we will add the component to Utility Bar in Sales App.
Image04 Screen Flow for Pop Up
Image05 Input Variables for event
Image06 Publish Screen Flow Event
Image07 Final Record Triggered Flow
Image08 Put the Platform Event Listener in Utility Bar
Video01 Sampe Case Result

Installation

V.1.1 (Additional Launch_when_current_URL_contains__c attribute)
Production
Sandbox
Source Code

V.1.0 (Initial Release)
Production
Sandbox
Source Code

Limitations and Considerations

  1. Only working on Lightning Interface.
  2. The targeted user should be in active session and has the page opened (can be idle) by the time event fired.
  3. Beware of the data that you passed to the platform event, although we can filter who can see the Screen Flow modal, we cannot filter the event data that being streamed to non targeted users browser because filtering happened at client side, not server side. I would suggest to just pass Id or generic flag to the input variables, and do GET inside your Screen Flow.
  4. Beware of Platform Event limitations as you may hit the limit faster (depends on your use case)

There you go! hope this can make your life a little bit easier. Please clap if you think this is useful, and comment if you have an idea to improve this, will try to help the best as I can.
Thanks.

--

--

Munawirrahman
Munawirrahman

Written by Munawirrahman

A dots connector. 22x Salesforce Certified. Open for consultation, Email: munawirrahman@gmail.com

Responses (6)