Newer Version Available

This content describes an older version of this product. View Latest

force:showToast

Displays a toast notification with a message.

A toast displays a message below the header at the top of a view. The message is specified by the message attribute.

This example displays a toast message “Success! The record has been updated successfully.”.

1showToast : function(component, event, helper) {
2    var toastEvent = $A.get("e.force:showToast");
3    toastEvent.setParams({
4        "title": "Success!",
5        "message": "The record has been updated successfully."
6    });
7    toastEvent.fire();
8}

This event is handled by the one.app container. It’s supported in Lightning Experience and Salesforce1 only. If used outside of Lightning Experience or Salesforce1, this event won’t be handled automatically. To use this event outside of one.app, create and wire up an event handler of your own.

Note

The background color and icon used by a toast is controlled by the type attribute. For example, setting it to success displays the toast notification with a green background and checkmark icon. This toast displays for 5000ms, with a close button in the top right corner when the mode attribute is dismissible.

Attribute Name Type Description
title String Specifies the toast title in bold.
message String Required. Specifies the message to display.
key String Specifies an icon when the toast type is other. Icon keys are available at the Lightning Design System Resources page.
duration Integer Toast duration in milliseconds. The default is 5000ms.
type String The toast type, which can be error, warning, success, or info. The default is other, which is styled like an info toast and doesn’t display an icon, unless specified by the key attribute. Available in API version 37.0 and later.
mode String The toast mode, which controls how users can dismiss the toast. The default is dismissible, which displays the close button. Available in API version 37.0 and later.
Valid values:
  • dismissible: Remains visible until you press the close button or duration has elapsed, whichever comes first.
  • pester: Remains visible until duration has elapsed. No close button is displayed.
  • sticky: Remains visible until you press the close buttons.