Lightning Web Component Library
Platform Show Toast Event
Descriptor
lightning-platform-show-toast-event
Experience
Lightning Experience
Documentation
Display toaster to provide feedback to a user following action, such as after a record is created.
You can style a toast to provide information, an error, success, or a warning. You can also configure the visibility of the toast. It can remain visible for three seconds until the user clicks to dismiss it, or a combination of both.
To trigger a toast from a Lightning web component, in the component’s JavaScript class, import ShowToastEvent from lightning/platformShowToastEvent. create a ShowToastEvent with a few parameters, and dispatch it. The app handles the rest.
In this example, when a user clicks the button the app displays a toast with the info variant, which is the default. The toast remains visible for 3 seconds or until the user clicks the close button, denoted by the X in the top right corner, which is also the default.
<template>
<lightning-button
label="Show Toast"
onclick={showToast}>
</lightning-button>
</template>