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..!!

No comments:

Post a Comment