Notifications Library

lightning:notificationsLibrary

Displays messages via notices and toasts. This component requires API version 41.0 and later.

For Aura components only. For LWC development, use lightning/platformShowToastEvent.

For Use In

Lightning Experience, Experience Builder Sites, Salesforce Mobile App

Messages can be displayed in notices and toasts. Notices alert users to system-related issues and updates. Toasts enable you to provide feedback and serve as a confirmation mechanism after the user takes an action.

Include one <lightning:notificationsLibrary aura:id="notifLib"/> tag in the component that triggers the notifications, where aura:id is a unique local ID. Only one tag is needed for multiple notifications.

Notices 

Notices interrupt the user’s workflow and block everything else on the page. Notices must be acknowledged before a user regains control over the app again. As such, use notices sparingly. They are not suitable for confirming a user’s action, such as before deleting a record. To dismiss the notice, only the OK button is currently supported.

Notices inherit styling from prompts in the Lightning Design System.

To create and display a notice, pass in the notice attributes using component.find('notifLib').showNotice(), where notifLib matches the aura:id on the lightning:notificationsLibrary instance.

Here’s an example that contains a button. When clicked, the button displays a notice with the error variant.

1<aura:component>
2    <lightning:notificationsLibrary aura:id="notifLib"/>
3    <lightning:button name="notice" label="Show Notice" onclick="{!c.handleShowNotice}"/>
4</aura:component>

This client-side controller displays the notice.

1({
2    handleShowNotice : function(component, event, helper) {
3        component.find('notifLib').showNotice({
4            "variant": "error",
5            "header": "Something has gone wrong!",
6            "message": "Unfortunately, there was a problem updating the record.",
7            closeCallback: function() {
8                alert('You closed the alert!');
9            }
10        });
11    }
12})

To create and display a notice, pass in the notice attributes using component.find('notifLib').showNotice(), where notifLib matches the aura:id on the lightning:notificationsLibrary instance.

Parameters 

ParameterTypeDescription
headerStringThe heading that’s displayed at the top of the notice.
titleStringThe title of the notice, displayed in bold.
messageStringThe message within the notice body. New lines are replaced by <br/> and text links by anchors.
variantStringChanges the appearance of the notice. Accepted variants are info, warning, and error. This value defaults to info.
closeCallbackFunctionA callback that’s called when the notice is closed.

Toasts 

Toasts are less intrusive than notices and are suitable for providing feedback to a user following an action, such as after a record is created. A toast can be dismissed or can remain visible until a predefined duration has elapsed.

Toasts inherit styling from toasts in the Lightning Design System.

To create and display a toast, pass in the toast attributes using component.find('notifLib').showToast(), where notifLib matches the aura:id on the lightning:notificationsLibrary instance.

Here’s an example that contains a button. When clicked, the button displays a toast with the info variant and remains visible until you click the close button, denoted by the X in the top right corner.

1<aura:component>
2    <lightning:notificationsLibrary aura:id="notifLib"/>
3    <lightning:button name="toast" label="Show Toast" onclick="{!c.handleShowToast}"/>
4</aura:component>

This client-side controller displays the toast.

1({
2    handleShowToast : function(component, event, helper) {
3        component.find('notifLib').showToast({
4            "title": "Success!",
5            "message": "The record has been updated successfully."
6        });
7    }
8})

Displaying Links in Toasts and Notices 

To display a link in the message, use the messageData attribute to pass in url and label values for the message string.

1({
2            handleShowToast : function(component, event, helper) {
3                component.find('notifLib').showToast({
4                "title": "Success!",
5                "message": "Record {0} created! See it {1}!",
6                "messageData": [
7                    'Salesforce',
8                    {
9                        url: 'http://www.salesforce.com/',
10                        label: 'here',
11                    }
12                ]
13            });
14        })

Using messageData is not supported for the Salesforce mobile app.

Parameters 

ParameterTypeDescription
titleStringThe title of the toast, displayed as a heading.
messageStringA string representing the message. It can contain placeholders in the form of {0} ... {N}. The placeholders are replaced with the links on messageData.
messageDataString[] | Objecturl and label values that replace the {index} placeholders in the message string.
variantStringChanges the appearance of the notice. Accepted variants are info, success, warning, and error. This value defaults to info.
modeStringDetermines how persistent the toast is. The default is dismissable. Valid modes are:
  • dismissable: 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.

Design Guidelines 

A notice appears when the system needs to communicate a message to the user; it doesn’t show up as a result of user action. A notice should rarely appear and generally should not be a part of a typical user flow. Contrastingly, a toast appears in reaction to a user action: creating, editing, deleting. For example, a user edits a record and saves it. For more information, see Messaging Design Guidelines.

Attributes 

NameDescriptionTypeDefaultRequired
bodyThe body of the component. In markup, this is everything in the body of the tag.Aura.Component[]

Methods 

NameDescriptionArgument NameArgument TypeArgument Description
showNoticeDisplays a notice with a message.noticeParamsMapParameters to customize your notice with values for variant, header, message, and closeCallback.
showToastDisplays a toast with a message.toastParamsMapParameters to customize your toast with values for variant, title, message, messageData, and mode.