You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How to display different types of custom toast message as Error, Success, Info and warning toast notifications on click button, uses of ShowToastEvent property in Salesforce Lightning Web Component — LWC
#44
Open
vijayk3327 opened this issue
Jul 14, 2023
· 0 comments
In this post we are going to learn about How to How to How to display different types of custom toast message as Error, Success, Info and warning toast message notifications on click button, uses of importing the ‘ShowToastEvent’ property in Javascript in Salesforce Lightning Web Component — LWC.
In this post we are going to learn about How to How to How to display different types of custom toast message as Error, Success, Info and warning toast message notifications on click button, uses of importing the ‘ShowToastEvent’ property in Javascript in Salesforce Lightning Web Component — LWC.
→ Get source code live demo link:-
Step 1:- Create Lightning Web Component HTML ➡ lwcDisplayToastMsg.html
`
Display Toast Notifications in Lightning Web Component (LWC)
`
Step 2:- Create Lightning Web Component Javascript ➡ lwcDisplayToastMsg.js
` import { LightningElement } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
export default class LwcDisplayToastMsg extends LightningElement {
displayToastError() {
const toastEvt = new ShowToastEvent({
title: 'Error',
message: 'Some Error Occurred',
variant: 'error',
mode: 'dismissable'
});
this.dispatchEvent(toastEvt);
}
displayToastSuccess() {
const toastEvt = new ShowToastEvent({
title: 'Success',
message: 'Submitted Successfully ',
variant: 'success',
mode: 'dismissable'
});
this.dispatchEvent(toastEvt);
}
displayToastWarning() {
const toastEvt = new ShowToastEvent({
title: 'Toast Warning',
message: 'Some Problem Occurred',
variant: 'warning',
mode: 'dismissable'
});
this.dispatchEvent(toastEvt);
}
displayToastInfo() {
const toastEvt = new ShowToastEvent({
title: 'Toast Info',
message: 'Data running in background',
variant: 'info',
mode: 'dismissable'
});
this.dispatchEvent(toastEvt);
}
}`
Step 3:- Create Lightning Web Component Meta XML ➡ lwcDisplayToastMsg.js-meta.xml
<?xml version="1.0" encoding="UTF-8"?> <LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata"> <apiVersion>45.0</apiVersion> <isExposed>true</isExposed> <targets> <target>lightning__AppPage</target> <target>lightning__RecordPage</target> <target>lightning__HomePage</target> </targets> </LightningComponentBundle>
→ Get source code live demo link:-
The text was updated successfully, but these errors were encountered: