SFDC Stop - Always the latest about Salesforce

Full Tutorial Series with videos, free apps, live sessions, salesforce consulting and much more.

Telegram logo   Join our Telegram Channel

Friday, 1 May 2020

How to display warnings in Salesforce ? | Become an #AwesomeAdmin using Platform Event Toast LWC

Hello Trailblazers,

I recently created a new generic toast component named as "Platform Event Toast LWC" which can be used to display warnings in Salesforce. I open sourced it on github and it can be accessed on this link:- https://github.com/rahulmalhotra/Platform-Event-Toast-LWC

Have you ever faced a requirement where you need to show warning message to the user who is trying to save a record but you also want that the record should be saved successfully without any restriction ?

In this post, we're going to learn how we can show warnings in Salesforce using Platform Event Toast LWC and take one step forward to become an #AwesomeAdmin.

The Platform Event Toast can be installed as an unmanaged package in any developer/sandbox/production environment by clicking on the links below:-

  1. Developer/Production Environment:- https://login.salesforce.com/packaging/installPackage.apexp?p0=04t7F000005ZBvB
  2. Sandbox Environment:- https://test.salesforce.com/packaging/installPackage.apexp?p0=04t7F000005ZBvB

Use Case

Let's say you wanna show a warning to the user who is updating the Annual Revenue of the account. The new annual revenue is >= $50,000 but the user forgot to update the rating to "Hot". In this scenario, the client doesn't want to restrict the user from saving the record but the user should know that the preferred rating for this account is "Hot"

Our AWESOME Salesforce Admin can fulfill this requirement using Platform Event Toast. All he has to do is to create a process builder on Account as shown below:-

Process Builder will run when an account record is created or edited as we want to show warning when a record is updated by the user.

We're setting the criteria that all of the conditions are met and we've added two conditions:-

  1. Annual Revenue >= $50,000
  2. Rating != Hot

We'll execute the process builder only when the specified changes are made to the record as we want to show warning only once.

AccountProcessCriteria.jpg (1366×628)

At the end, we added an action where we're creating a Toast Event record by setting up properties of toast as shown below:-

Note:- Key is a required field and must be filled. A key is used to uniquely identify a toast event when it's displayed on a page. Moreover, it'll help you as an admin to debug and find the process builder very easily if you're setting up the key as:- ProcessBuilderName_ConditionName as a key should be unique.

Once your process builder is ready and activated, it's time to add our component to the lightning page. We just have to make sure that we're adding the same key here as we specified in the process builder:-

We can leave the other fields empty for this toast as we've setup everything from the process builder. In case, we haven't specified value of other fields in the process builder, we can fill those fields here. Note that if you've added values in the process builder and in the component as well the values from process builder have higher priority and will override the values set in the component.

Once you've setup the toast successfully, you'll see the below result when Account's Annual Revenue >= $50,000 and Rating != Hot

This is just a single use case. However, there can be multiple use cases where you can use this toast. You also have an option as:- Run in System Mode which will allow a toast to run in system mode i.e. the toast will be visible to all users of the org if the toast exists on the page that is opened by the user. This option can be used to create Org Wide Announcements by adding the toast as a part of utility bar so that it's available at application level no matter which page is opened by the user.

If you want to know in detail about the Run in System Mode feature, let me know in the comments down below and I'll write another blog on the same.

Considerations while using Platform Event Toast

Let's have a look at linkedin post below that I published when I created this Platform Event Toast:-

As you can see linkedin post above, there is a comment by René Winkelmeyer @muenzpraeger who is an Architect, Developer Evangelism at Salesforce. He highlighted that the Platform Event Toast will work for small/medium size orgs, but may cause issue in large organizations where we have a large number of users or we're using Platform Events at various places for different purposes. As platform events work in real time, they've limitations on the number of event notifications, concurrent subscribers in a 24 hour period. You can have a detailed look at the limits here:- https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_event_limits.htm

Thanks René for highlightning this 😊

You can also have a look at the video for the same below:-

If you liked this post, make sure to share it in your network and let me know your feedback in the comments down below.

Happy Trailblazing..!!


  1. I tried to implement this for community page, my scenario is to display custom toast message whenever user creates a Case. Looks like it is not working for community users.

    1. Hi Hemanth, have you placed the lightning component on the community page?

  2. Hi Rahul, I am using it to detect duplicate Opportunity record. my process+flow is working fine and creating platform event record successfully. But I am not able to see toast message on Opportunity record. I have one more question, what if 2 Opportunity records are open in 2 tabs. how it will detect on which Opportunity record page to show toast or not? thanks

    1. To answer your question, the platform event toast by default runs in user mode, so, if you've two opportunity records in two different tabs and you've the component embedded on the opportunity detail page, you'll see both the tabs with toast, if you want to display only on a particular record page, you can send the record id as "key" from the process builder and you need to update the platform event toast js file a little so that it checks for that particular key and compare it with the current record id. Although, it's a good use case, I'll try to publish an update with record id included asap.

  3. In continuation to my last comment : this is error I see on console :
    "Error in Platform Event Toast" which is from lwc component. trying to find root cause.

    1. Hi, you must be getting the error details as well along with the error in platform event toast. Can you share those?

    2. My bad, as i have to create Platform event manually, api name was wrong for event. Its fixed. working as expected. Thanks for prompt reply.

    3. Ohh..okay, you can install the unmanaged package otherwise so that everything is created and ready for use.

  4. HOW TO TRIGGER: A user friendly validation error message from record triggered flow?

    1. It'll follow the same process as we're doing in case of process builder