display different types of toast message in lwc -- w3web.net

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 | display custom toast notification in lwc

Hey guys, today 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.

A lighting component send a toast notification that pops up to alert users of a success, error, or warning. A toast can also simply provide information. To display a toast notification in Lightning Experience or Experience Builder sites, import ShowToastEvent from the lightning/platformShowToastEvent module. Know more about toast notification in lwc

Parameters of toast notification

PARAMETER TYPE DESCRIPTION
title String (Required) The title of the toast, displayed as a heading.
message String (Required) A string representing the body of the message. It can contain placeholders in the form of {0} … {N}. The placeholders are replaced with the links on messageData.
messageData String[] or Object url and label values that replace the {index} placeholders in the message string.
variant String Changes the appearance of the notice. Toasts inherit styling from toasts in the Lightning Design System. Valid values are: info (default), success, warning, and error.
mode String Determines how persistent the toast is. Valid values are: dismissible (default), remains visible until you click the close button or 3 seconds has elapsed, whichever comes first; pester, remains visible for 3 seconds and disappears automatically. No close button is provided; sticky, remains visible until you click the close button.

Files we used to create custom toast notification in LWC

lwcDisplayToastMsg.html LWc HTML File Template HTML file to create different types of toast message in lwc
lwcDisplayToastMsg.js LWC JavaScript File It’s hold a javascript on click function to display the different types Toast Message Notifications using ‘ShowToastEvent’ element lwc.
lwcDisplayToastMsg.js-meta.xml XML Meta File It is used to where this lightning web component file you want to display as like lightning__AppPage, lightning__RecordPage, lightning__HomePage.

Final Output

display different types of toast message in lwc -- w3web.net

Other related post that would you like to learn in LWC

  • Find the below steps

Create Lightning Web Component HTML

Step 1:- Create Lightning Web Component HTML ➡ lwcDisplayToastMsg.html

SFDX:Lightning Web Component ➡ New ➡ lwcDisplayToastMsg.html

lwcDisplayToastMsg.html [Lightning Web Component HTML]

Create Lightning Web Component Javascript

Step 2:- Create Lightning Web Component Javascript ➡ lwcDisplayToastMsg.js

SFDX:Lightning Web Component ➡ New ➡ lwcDisplayToastMsg.js

lwcDisplayToastMsg.js [LWC JavaScript File]

Create Lightning Web Component Meta XML

Step 3:- Create Lightning Web Component Meta XML ➡ lwcDisplayToastMsg.js-meta.xml

SFDX:Lightning Web Component ➡ New >> lwcDisplayToastMsg.js-meta.xml

lwcDisplayToastMsg.js-meta.xml [LWC Meta Data XML]

display different types of toast message in lwc -- w3web.net

Further post that would you like to learn in LWC

Create a Flyout Account, It will help you to grow make more money for a better living.

If you think you and your family members also like to earn money in additional time, then go this link. In this site, you can earn money for the lifetime at low effort. To Earn Unlimited Everyday With This Trick, Sign Up Free.. Get Started for Free

Check Out:- Earn Unlimited Everyday With This Trick:- Click Here

Related Topics | You May Also Like

Hi, This is Vijay behind the admin and founder of w3web.net. I am a senior software developer and working in MNC company from more than 8 years. I am great fan of technology, configuration, customization & development. Apart of this, I love to write about Blogging in spare time, Working on Mobile & Web application development, Salesforce lightning, Salesforce LWC and Salesforce Integration development in full time.

Leave a Comment