Lightning Aura Components – How to Hide Toast in Service Cloud Console

We are using a backgroundutilityitem component, where we fire a toast event – https://developer.salesforce.com/docs/component-library/bundle/force:showToast/documentation

I know it shows the toast, and it will hide it based on "mode" of the toast. But is there a way we can fire an event to close the toast?

For example, some field changes, we fire the event to close the toast.

Overall summary of what i am building is here – Show pop-up or toast or banner in Lightning Service cloud console

But to summarize, whenever a call comes in omni channel, we show a toast "A call is waiting for you" in lightning service cloud console. I am done with this. Mode of the toast is "sticky", so it will stay there until agent manually closes it.

We also want the functionality where if agent accepts the call or if call gets declined (i can capture both events in my backgroundutilityitem), i want to close the toast (if its displayed).

Since this is a backgroundutilityitem component, putting a custom component (toast or a modal) in it will not display on UI. So we are stuck with using standard force:showToast event (to best of my knowledge).

Best Answer

No, there's no way to close the standard toast once you've popped it up. Both lightning:notificationsLibrary and force:showToast only have functionality for opening the toast. You'll have to write your own custom component.

Related Topic