How can developers display user notification banners using the ShowToastEvent module?
Answer
Basics: A toast is a temporary banner that confirms an action or reports a problem without navigating away. It is the standard way to give feedback after a save, delete or failed callout.
How it works:
import { ShowToastEvent } from 'lightning/platformShowToastEvent';.- Build the event with properties:
title(bold header),message(body),variant(info,success,warning,error) andmode(dismissible,pester,sticky). - Dispatch it from the component:
this.dispatchEvent(evt). The container (Lightning page) renders it. messageDatalets you add links:message: 'Created {0}',messageData: [{ url: '/' + id, label: 'record' }].
Advanced / deep dive: Modes: dismissible stays until the user closes it or about 3 seconds pass; pester stays about 3 seconds with no close button; sticky stays until the user closes it. Use sticky for errors needing attention. Toast support depends on the container: it works in Lightning Experience, the Salesforce mobile app and Experience Builder sites in supported setups, but not in Lightning Out or standalone apps, so verify for your runtime and for LWR sites. Toasts are for feedback, not validation; use lightning-input setCustomValidity and reportValidity for field errors, or lightning-messages in forms. Keep text concise and localize via Custom Labels (@salesforce/label/c.Label_Name). For accessibility, the toast uses a live region, but avoid relying on it alone for critical errors; show persistent inline messages as well. Flows have their own toast action and Aura has .