Toast Builder
A convenient builder-pattern utility for displaying toast notifications.
Why Toast Builder?
- Fluent API - Keep your LWC code clean and minimalistic with the Toast fluent API.
- Automatic Error Handling - Just pass the error directly to the message and it will be handled as a single string.
Quick Start
❌❌❌
js
const event = new ShowToastEvent({
title: 'Success!',
message: 'Record {0} created! See it {1}!',
messageData: [
'Salesforce',
{
url: 'http://www.salesforce.com/',
label: 'here',
},
],
}
);
this.dispatchEvent(event);✅✅✅
js
import Toast from 'c/toast';
// Show a success toast
Toast.Builder(this)
.label('Success')
.message('Record saved successfully!')
.showSuccess();
// Show an error toast with a reduced error message from the error service
someApexMethod()
.then(result => {
// ...
})
.catch(error => {
Toast.Builder(this).message(error).sticky().showError(); // The label will default to 'Error'
});