Toast are the message box or you can say notification box which you can use to show messages/notification on top of the view.

Toast displays a message below in the header at the top of the view.

In this blog, we are going to learn about how to show toast in salesforce Lightning record page by using “force:showToast”.

Note:-

Toast event is handled by the one.app container and it is supported in Lightning Experience, Salesforce app, and Lightning communities.

force:showToast is not available on login pages.

Now let’s learn attribute of the toast.

Toast Attributes:-

  1. title: Specifies the title of toast.
  2. message: Specifies the message to display.
  3. messageTemplate: If you want to override the ‘message’ which is specified in message attribute then you can use this attribute along with ‘messageTemplateData’.
  4. messageTemplateData: To show the overridden message you must use this attribute.
  5. key: Specifies the icon on toast when the type is not defined.Icon keys are available at the Lightning Design System Resources page.
  6. duration: Specifies the duration of toast to be shown.after specified duration toast will automatically disappear.
  7. type: the toast type which can be “error”, “warning”, “success”, “info”.The default is “other”, which is styled like an info toast and doesn’t display an icon, unless specified by the “key” attribute.
  8. mode: Controls how users can dismiss the toast. The default is “dismissible”, which displays the close button.valid mode values are:-
  • 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.

Now we will focus on building such interesting ‘Toast’ in our environment.

Create lightning component named “ToastComponent” and paste below code in your component.

ToastComponent.cmp

 

 

Now our component is ready.

Next step is to show our component on home page.

Go to Home Page and click on “Edit Page” under setup menu.

CloudFountain: Edit Salesforce Home Page.

Select “ToastComponent” under “Custom” tab and drag it below Assistant(right side of page).

CloudFountain: Show Toast Component on Salesforce Home Page.

You can see your “ToastComponent” like below –

CloudFountain: View Toast Component on Salesforce Home Page.

Click on “Save” and “Activate” your component to system default (for all users) and refresh home page.

Salesforce Lightning Component available to all users.

Let’s test our component.

  1. Click on “Information” button and see “Information ToastSalesforce Information Toast Message
  2. Click on “Error” button and see “Error ToastSalesforce Error Toast Message
  3. Click on “Warning” button and see “Warning ToastSalesforce Warning Toast Message
  4. Click on “Success” button and see “Success ToastSalesforce Success Toast Message

Excellent Job…!!! Keep Learning…

Related posts