By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
horizontal-light horizontal-dark
  • Tutorials
    • Salesforce Flow
    • Salesforce Integration
    • Salesforce Tools
    • Apex Development
    • Lightning Web Components
    • AI and Automation
    • Salesforce Errors
    • DevOps and Deployment
  • Interview Questions
    • Salesforce Developer Interview Questions
  • Career & Certification
    • Salesforce Certification Guide 2026
  • More
    • Privacy Policy
    • Disclaimer
    • Terms & Conditions
    • Contact
SalesforceCornerSalesforceCorner
Search
  • Tutorials
    • Salesforce Flow
    • Salesforce Integration
    • Salesforce Tools
    • Apex Development
    • Lightning Web Components
    • AI and Automation
    • Salesforce Errors
    • DevOps and Deployment
  • Interview Questions
    • Salesforce Developer Interview Questions
  • Career & Certification
    • Salesforce Certification Guide 2026
  • More
    • Privacy Policy
    • Disclaimer
    • Terms & Conditions
    • Contact
Follow US
Home » How to Show a Toast Message in Salesforce LWC
Uncategorized

How to Show a Toast Message in Salesforce LWC

Learn how to display toast notifications in Salesforce LWC using real-world examples and best practices.

Neha Panwar
By
Neha Panwar
ByNeha Panwar
Salesforce Developer and Technical Writer
Neha Panwar is a Salesforce developer and technical writer who shares practical tutorials, Apex guides, and real-world solutions for developers. She focuses on simplifying Salesforce concepts,...
Follow:
- Salesforce Developer and Technical Writer
Last updated: 2026/06/13
Share
SHARE

A user clicks the Save button, the record is successfully created, but nothing changes on the screen. There is no confirmation message, no success notification, and no indication that the operation completed successfully. Most users assume something failed and click the button again. As a result, duplicate records, repeated requests, and unnecessary support tickets become common. This is exactly why understanding How to Show a Toast Message in Salesforce LWC is an essential skill for Salesforce developers.

Contents
Image 1: Featured ImageAlt TextImage PromptWhat Is a Toast Message in Salesforce LWC and How Does It Work?Why Should You Show a Toast Message in Salesforce LWC?How Toast Notifications Work in Salesforce LWCHow to Show a Toast Message in Salesforce LWCImage 2: Success Toast ExampleAlt TextImage PromptUnderstanding Toast Message AttributesReal Developer ExperienceCommon Business Scenarios for Toast MessagesScreenshot OpportunityAdditional Internal Linking OpportunitiesHow to Show an Error Toast Message in Salesforce LWCImage 3: Error Toast NotificationAlt TextImage PromptHow to Show a Warning Toast Message in Salesforce LWCImage 4: Warning Toast NotificationAlt TextImage PromptHow to Show an Information Toast Message in Salesforce LWCToast Message Modes in Salesforce LWCHow to Show a Toast Message in Salesforce LWC After an Apex CallImage 5: Toast Message After Apex CallAlt TextImage PromptCommon Errors and SolutionsToast Message vs Custom ModalBest Practices for Toast Messages in Salesforce LWCMistakes to AvoidFrequently Asked QuestionsWhat is ShowToastEvent in Salesforce LWC?Can I show a toast message without Apex?How many toast variants are available?Can I customize the title and message?What is the best mode for error messages?Can toast notifications be used after record creation?Are toast notifications supported in Lightning Experience?Do toast notifications work on mobile devices?Can I display dynamic values inside a toast message?Should I use toast messages or modal windows?Outbound ResourcesConclusionImage 6: Final ImageAlt TextImage Prompt

Developers often use toast notifications. provide immediate feedback after a user performs an action. Whether a user creates a Lead, updates an Opportunity, submits a custom form, or triggers an Apex method, a toast message confirms the outcome without interrupting the workflow. Instead of building custom popups or redirecting users to another page, Salesforce provides a built-in framework called ShowToastEvent that displays lightweight notifications directly within the Lightning Experience interface.

In real-world Salesforce projects, toast messages are everywhere. Users expect visual confirmation after every important action. A well-designed Lightning Web Component not only performs the required business logic but also communicates clearly with users. Toast notifications help achieve that goal with minimal code and maximum usability.

Image 1: Featured Image

Alt Text

How to Show a Toast Message in Salesforce LWC success notification

Image Prompt

Realistic Salesforce Lightning Experience showing a green success toast notification after saving a record, authentic Salesforce UI, Lightning Design System styling, enterprise CRM interface, screenshot style, ultra realistic software environment, natural user interface, no illustrations, no AI art appearance

What Is a Toast Message in Salesforce LWC and How Does It Work?

A toast message is a temporary notification displayed in the Salesforce user interface to inform users about the outcome of an action. These notifications typically appear in the upper-right corner of the screen and disappear automatically after a few seconds unless configured otherwise.

Toast messages are commonly used for:

  • Record creation
  • Record updates
  • Record deletion
  • Form submissions
  • Validation feedback
  • Apex call responses
  • Integration notifications

Instead of forcing users to refresh the page or navigate elsewhere, Salesforce immediately displays feedback through a notification. This creates a smoother user experience and reduces uncertainty.

For example, after creating a new Account record, Salesforce may display:

Account Created Successfully

Similarly, if a validation rule prevents a record update, Salesforce can display an error notification explaining the issue.

Why Should You Show a Toast Message in Salesforce LWC?

Many developers focus on functionality and business logic while overlooking user feedback. However, user experience plays a major role in application adoption.

Imagine a sales representative updating an Opportunity through a custom Lightning Web Component. The record saves successfully, but no confirmation appears. Since the user receives no feedback, they may click Save again, assuming the operation failed.

This often leads to:

  • Duplicate records
  • User confusion
  • Additional support requests
  • Poor user experience

Toast notifications solve these problems by providing instant confirmation.

In production environments, developers frequently display toast notifications after:

Lightning Data Service operations
[Internal Link Opportunity: Lightning Web Components Tutorial for Beginners]

Apex method execution
[Internal Link Opportunity: Imperative Apex Call in LWC]

Data refresh operations
[Internal Link Opportunity: RefreshApex in LWC Salesforce]

API responses and integrations
[Internal Link Opportunity: Salesforce REST API Tutorial]

As a result, users gain confidence in the application and understand exactly what happened after every action.

How Toast Notifications Work in Salesforce LWC

The process is straightforward.

User Clicks Button
        ↓
JavaScript Method Executes
        ↓
ShowToastEvent Created
        ↓
Event Dispatched
        ↓
Toast Notification Displayed

Once the ShowToastEvent is dispatched, Salesforce automatically renders the notification.

Unlike custom modals, developers do not need additional HTML, CSS, or JavaScript frameworks.

How to Show a Toast Message in Salesforce LWC

The first step is importing ShowToastEvent into the component.

import { ShowToastEvent } from 'lightning/platformShowToastEvent';

This module provides access to Salesforce’s native toast notification framework.

Next, create a method that dispatches the notification.

showSuccessToast() {

    const toast = new ShowToastEvent({

        title: 'Success',
        message: 'Record saved successfully',
        variant: 'success'

    });

    this.dispatchEvent(toast);

}

When the method executes, Salesforce automatically displays a success notification.

Image 2: Success Toast Example

Alt Text

How to Show a Toast Message in Salesforce LWC success message example

Image Prompt

Realistic Salesforce Lightning page displaying green success toast notification after record creation, authentic Salesforce CRM environment, screenshot style, ultra realistic user interface, professional business application appearance

To trigger the notification, connect the method to a Lightning button.

<template>

    <lightning-button
        label="Show Toast"
        onclick={showSuccessToast}>
    </lightning-button>

</template>

After clicking the button, the notification appears instantly.

Understanding Toast Message Attributes

Every toast notification contains several attributes that control how it behaves.

AttributeDescription
titleNotification heading
messageMain content displayed to users
variantSuccess, Error, Warning, Info
modeControls visibility behavior

Example:

new ShowToastEvent({

    title: 'Success',
    message: 'Account created successfully',
    variant: 'success',
    mode: 'dismissable'

});

The title should clearly communicate the outcome. Meanwhile, the message should provide additional context. Selecting the correct variant helps users quickly understand the type of notification being displayed.

Real Developer Experience

I first encountered this requirement while building a custom Lead Management application for a sales team. Users were creating Leads through a Lightning Web Component, but there was no visual confirmation after the save operation completed. Several users clicked the Save button multiple times because they assumed the request failed. After adding a simple success toast notification, duplicate submissions dropped significantly and the overall user experience improved immediately.

Common Business Scenarios for Toast Messages

Toast notifications are used in almost every Salesforce implementation.

A sales team may receive a success message after creating a Lead. Customer service agents often see warning notifications when important Case details are missing. Similarly, administrators may display error messages when validation rules prevent record updates.

Integration projects also benefit from toast notifications. For example, after data is successfully synchronized from an external application, users can receive immediate confirmation without refreshing the page.

Because these notifications require very little code, they provide one of the highest user experience improvements for the effort involved.

Screenshot Opportunity

[Screenshot: Salesforce Lightning Page Showing Success Toast Notification]

Additional Internal Linking Opportunities

[Internal Link Opportunity: Parent to Child Communication in LWC]

[Internal Link Opportunity: Salesforce Wire Decorator in LWC]

[Internal Link Opportunity: VS Code Setup for Salesforce Development]

[Internal Link Opportunity: Salesforce CLI Installation and Setup Guide]

[Internal Link Opportunity: Apex Trigger in Salesforce]

[Internal Link Opportunity: Salesforce Developer Console Tutorial]

How to Show an Error Toast Message in Salesforce LWC

Success notifications are useful when everything works correctly, but production applications must also handle failures gracefully. Users should never be left wondering why an operation failed. Instead, a clear error notification should explain the problem immediately.

Error toast messages are commonly displayed when:

  • Apex exceptions occur
  • Validation rules fail
  • Required fields are missing
  • API requests fail
  • Record updates are blocked

The implementation is very similar to a success notification.

showErrorToast() {

    const toast = new ShowToastEvent({

        title: 'Error',
        message: 'Unable to save the record.',
        variant: 'error'

    });

    this.dispatchEvent(toast);

}

Image 3: Error Toast Notification

Alt Text

How to Show a Toast Message in Salesforce LWC error notification

Image Prompt

Realistic Salesforce Lightning Experience displaying red error toast notification after failed record update, authentic Salesforce interface, Lightning Design System styling, screenshot style, ultra realistic CRM application, natural software environment

A good error message should help users understand what happened. Generic messages such as “Something went wrong” often create frustration because users do not know what action to take next.

How to Show a Warning Toast Message in Salesforce LWC

Warning notifications are useful when users need to review information before continuing. Unlike error notifications, warnings do not necessarily indicate a failed operation.

Consider a scenario where a sales representative attempts to close an Opportunity without entering important business information. Salesforce may still allow the action, but displaying a warning message encourages users to verify the data before proceeding.

showWarningToast() {

    const toast = new ShowToastEvent({

        title: 'Warning',
        message: 'Please review the Opportunity details.',
        variant: 'warning'

    });

    this.dispatchEvent(toast);

}

Image 4: Warning Toast Notification

Alt Text

How to Show a Toast Message in Salesforce LWC warning notification

Image Prompt

Realistic Salesforce Lightning interface showing yellow warning toast notification, professional CRM environment, authentic Lightning Design System styling, screenshot style, ultra realistic business application interface

Warning notifications are especially useful in approval processes, Opportunity management, and custom validation scenarios.

How to Show an Information Toast Message in Salesforce LWC

Information notifications provide users with updates that are neither success nor error related. These messages are often used to communicate the status of background operations.

showInfoToast() {

    const toast = new ShowToastEvent({

        title: 'Information',
        message: 'Background process started successfully.',
        variant: 'info'

    });

    this.dispatchEvent(toast);

}

Examples include:

  • Background synchronization started
  • Report generation in progress
  • Data import initiated
  • Integration request submitted

Information notifications help users understand system activity without interrupting their workflow.

Toast Message Modes in Salesforce LWC

Salesforce provides three different modes that control how long a toast notification remains visible.

ModeDescription
dismissableUser can manually close the notification
pesterAutomatically disappears after a few seconds
stickyRemains visible until manually closed

Example:

new ShowToastEvent({

    title: 'Success',
    message: 'Account created successfully',
    variant: 'success',
    mode: 'sticky'

});

Choosing the correct mode improves usability.

Success notifications generally work well with dismissable mode. On the other hand, critical warnings and errors often benefit from sticky mode because users are less likely to miss important information.

How to Show a Toast Message in Salesforce LWC After an Apex Call

One of the most common real-world use cases involves displaying notifications after Apex execution.

Imagine a custom Lead Creation component where users create Leads through a Lightning Web Component. After the Apex method completes successfully, Salesforce displays a success notification.

import createLead from '@salesforce/apex/LeadController.createLead';

handleCreateLead() {

    createLead()

        .then(() => {

            this.dispatchEvent(
                new ShowToastEvent({
                    title: 'Success',
                    message: 'Lead created successfully.',
                    variant: 'success'
                })
            );

        })

        .catch(error => {

            this.dispatchEvent(
                new ShowToastEvent({
                    title: 'Error',
                    message: error.body.message,
                    variant: 'error'
                })
            );

        });

}

This pattern is used extensively in enterprise Salesforce projects because it provides immediate feedback after server-side operations.

Image 5: Toast Message After Apex Call

Alt Text

How to Show a Toast Message in Salesforce LWC after Apex call

Image Prompt

Realistic Salesforce Lightning Experience displaying successful Apex response with green toast notification, Visual Studio Code showing Apex controller code, enterprise CRM environment, screenshot style, ultra realistic software development workspace

Common Errors and Solutions

ErrorCauseSolution
Toast not displayingShowToastEvent not importedImport ShowToastEvent correctly
Error message not shownApex exception not handledAdd a catch block
Multiple notifications appearEvent fired multiple timesReview component logic
Wrong variant displayedInvalid variant valueUse success, error, warning, or info
Message disappears too quicklyIncorrect mode selectedUse sticky mode when required

Toast Message vs Custom Modal

Developers often ask whether they should use a toast notification or a modal window.

FeatureToast MessageModal Window
User FeedbackQuickDetailed
User Action RequiredNoUsually Yes
Screen SpaceMinimalLarge
Performance ImpactVery LowHigher
Best Use CaseNotificationsConfirmations

Toast notifications are ideal when users simply need feedback. Modal windows are more suitable when users must review information or make decisions before continuing.

Best Practices for Toast Messages in Salesforce LWC

Keep notification messages short and meaningful. Users should immediately understand whether an operation succeeded or failed.

Use the correct variant for each situation. Error notifications should never appear as success messages, and warning notifications should not be used for informational updates.

Whenever possible, display notifications after important actions such as record creation, record updates, form submissions, and Apex operations.

In addition, avoid displaying multiple notifications simultaneously because excessive messages can overwhelm users and reduce effectiveness.

Developers should also test notifications across desktop and mobile experiences to ensure consistent behavior.

Mistakes to Avoid

One common mistake is using generic error messages. Users gain very little value from messages such as “Something went wrong.”

Another mistake involves displaying notifications for every minor action. Too many messages create notification fatigue and reduce their effectiveness.

Some developers also forget to handle Apex exceptions properly. A successful operation may display a toast notification, but error scenarios should always be handled as well.

Frequently Asked Questions

What is ShowToastEvent in Salesforce LWC?

ShowToastEvent is a Salesforce event used to display toast notifications in Lightning Web Components.

Can I show a toast message without Apex?

Yes. Toast notifications can be displayed entirely through client-side JavaScript.

How many toast variants are available?

Salesforce supports success, error, warning, and information variants.

Can I customize the title and message?

Yes. Both values can be dynamically generated.

What is the best mode for error messages?

Sticky mode is often preferred because users are less likely to miss important errors.

Can toast notifications be used after record creation?

Yes. This is one of the most common use cases.

Are toast notifications supported in Lightning Experience?

Yes. They are fully supported.

Do toast notifications work on mobile devices?

Yes. Salesforce mobile applications support toast notifications.

Can I display dynamic values inside a toast message?

Yes. Developers frequently display record names, IDs, and Apex response messages.

Should I use toast messages or modal windows?

Use toast notifications for quick feedback and modal windows for detailed user interaction.

Outbound Resources

Add these actual links in WordPress:

  • Salesforce Lightning Web Components Documentation
  • Salesforce Component Library
  • Salesforce Trailhead LWC Modules

Conclusion

Understanding How to Show a Toast Message in Salesforce LWC is an important skill for every Salesforce developer. Toast notifications improve user experience by providing immediate feedback after record operations, Apex calls, validations, and integrations. Although the implementation requires only a few lines of code, the impact on usability is significant.

Whether you’re building a simple form or a complex enterprise application, toast notifications help users understand what happened and reduce confusion. By using ShowToastEvent correctly, choosing the right notification type, and following best practices, you can create Lightning Web Components that feel more professional, responsive, and user-friendly.

Image 6: Final Image

Alt Text

How to Show a Toast Message in Salesforce LWC success error warning and info examples

Image Prompt

Realistic Salesforce Lightning Experience displaying success, error, warning, and information toast notifications on a Salesforce record page, authentic Lightning Design System interface, screenshot style, ultra realistic CRM environment, professional enterprise software appearance

Share This Article
Facebook Email Print
ByNeha Panwar
Salesforce Developer and Technical Writer
Follow:
Neha Panwar is a Salesforce developer and technical writer who shares practical tutorials, Apex guides, and real-world solutions for developers. She focuses on simplifying Salesforce concepts, integrations, and backend development to help beginners and professionals learn faster.
Leave a Comment Leave a Comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Latest Post

Fix unable to lock row error
How to Fix UNABLE_TO_LOCK_ROW Error in Salesforce
Salesforce Errors
How to fix SOQL 101 error
How to Fix Too Many SOQL Queries: 101 Error in Salesforce
Salesforce Errors
How to create a Lightning Web component
How to Create Your First Lightning Web Component in Salesforce
Lightning Web Components
Salesforce access management infographic
When Should You Use Permission Sets Instead of Profiles in Salesforce?
Salesforce Admin
Salesforce prompt builder UI concept
What Is a Prompt Template in Salesforce? Explained with Real Examples
AI and Automation

Stay Updated with Salesforce Tutorials

Get the latest Salesforce guides, tutorials, and developer tips delivered to your inbox.
slaesforce corner mascot

Explore More Topics

  • salesforce developer
  • salesforce admin
  • salesforce tutorial
  • Salesforce Development
  • Salesforce Admin
  • salesforce security
  • Salesforce Tools
  • Salesforce Tutorials
  • Salesforce Beginner Guide
  • lightning web components
  • salesforce automation
  • Lightning Web Components
  • salesforce apex
  • salesforce lwc
  • Apex Development
horizontal-dark-transparent

Learn Salesforce development with practical tutorials, Apex guides, integration examples, and real-world solutions for developers.

  • Quick Links:
  • About
  • Contact
  • Privacy Policy
  • Disclaimer
  • Terms & Conditions
Facebook Twitter Youtube Linkedin-in

Salesforce Corner © 2026

Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?