Salesforce · Development
Show Toast Real-Time When a Backend Flow Finishes Using Flow, Platform Event, and LWC
This guide covers how to notify users in real time when an asynchronous backend Flow finishes, leveraging Platform Events and Lightning Web Components (LWC) — with no Apex required.
This is an advanced and powerful pattern: use a Platform Event to decouple the Flow from the UI, so that even an autolaunched Flow running in the background can cause a toast to appear in the user's UI via an LWC.
Platform Events are technically a special kind of custom object — their Deployment Status is set to “Deployed” and Event Type is set to “Platform Event.”
Why use a Platform Event?
Normally:
- Autolaunched Flow → no UI → cannot directly show a toast.
- LWC running the Flow → can show a toast, but only if it's running in the same context.
With a Platform Event:
- The Flow publishes a Platform Event at the end (with info like "show toast").
- A Lightning Web Component (LWC) subscribed to that event (on a Lightning page) receives it.
- The LWC then shows a toast — even if the Flow ran completely in the background (e.g. triggered by Process Builder, a Record-Triggered Flow, or Apex).
So: Flow = backend logic → emits the Platform Event. LWC = UI subscriber → listens and shows the toast.
Step-by-step setup
Step 1: Create a Platform Event
Create a Platform Event named Show_Toast__e with three custom text fields:
- Title —
Title__c(Text) - Message —
Message__c(Text) - Variant —
Variant__c(Text)
Step 2: Build the autolaunched Flow (backend)
At the end of the Flow, add a Create Record element and configure it to create a single record of type Show_Toast__e, setting field values:
Title__c→ "Success"Message__c→ "Backend flow completed!" (e.g. "Successfully updated.")Variant__c→ "success"
Done — the Flow now emits an event to notify that it finished.
Step 3: Build the LWC (frontend)
The LWC subscribes to /event/Show_Toast__e. When it receives an event, it shows a toast.
//showToastSubscriber.js
import { LightningElement, track } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { subscribe, unsubscribe, onError } from 'lightning/empApi';
export default class ShowToastSubscriber extends LightningElement {
channelName = '/event/Show_Toast__e';
subscription = {};
connectedCallback() {
this.handleSubscribe();
this.registerErrorListener();
}
disconnectedCallback() {
this.handleUnsubscribe();
}
handleSubscribe() {
const messageCallback = (response) => {
const payload = response.data.payload;
const title = payload.Title__c;
const message = payload.Message__c;
const variant = payload.Variant__c;
this.dispatchEvent(new ShowToastEvent({
title: title,
message: message,
variant: variant
}));
};
subscribe(this.channelName, -1, messageCallback).then(response => {
console.log('Successfully subscribed to channel', response);
this.subscription = response;
}).catch(error => {
console.error('Error subscribing to platform event', error);
});
}
handleUnsubscribe() {
unsubscribe(this.subscription, response => {
console.log('Unsubscribed', response);
});
}
registerErrorListener() {
onError(error => {
console.error('Received error from empApi: ', JSON.stringify(error));
});
}
}
//showToastSubscriber.html
<template>
<!-- No UI needed; it just listens -->
</template>
//showToastSubscriber.js-meta.xml
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>59.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__AppPage</target>
<target>lightning__HomePage</target>
<target>lightning__RecordPage</target>
</targets>
</LightningComponentBundle>
Step 4: Deploy and add the LWC to a Lightning page
- Deploy the LWC component to your org.
- Go to App Builder (e.g. Home page, Record page).
- Drag
showToastSubscriberonto the page. - Save and activate.
Step 5: Test it out
- Trigger the Flow (e.g. via a button, action, or backend automation).
- Once the Flow finishes, it creates a
Show_Toast__erecord. - The LWC detects it in real time and shows a toast.
Summary
- Backend → autolaunched Flow → publishes a Platform Event.
- Frontend → LWC on a Lightning page → subscribes → shows a toast.
Bonus tip
You can customise the Flow to send different messages or status types (Success, Error, Warning) based on logic branches.
Final thoughts
This zero-Apex solution is ideal for admins and low-code developers who want to deliver a responsive user experience. With Platform Events + Flow + LWC, users get real-time feedback — without clicking refresh or writing any Apex.
Want real-time UX like this in your Salesforce org?
Talk to the team about building event-driven automation for your business.
Book a free strategy sessionor email sales@futurepulse.ai