function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Yogendra JangidYogendra Jangid 

How to capture standard showtoast event in lwc

I am writing a custom listner to lightning showtoast in my lwc application. 
constructor() {
        super();
        this.addEventListener('lightning__showtoast', this.handleNotification);
    }

    handleNotification() {
        //do something here
    }

this works fine when I fire the toast event explicitly via code. But when I use the lightning navigation, the standard toast events are fired.

Pop up is opened through the Navigation
navigateToRecordEditPage(event, recordId) {
        event.preventDefault();
        this[NavigationMixin.Navigate]({
            type: 'standard__recordPage',
            attributes: {
                recordId: recordId,
                objectApiName: this.records.relatedSobjectApiName,
                actionName: 'edit'
            }
        });
    }
Once the records are saved, the toast event is fired but same is not caught in the handler created. 
Does anyone have any idea how to make it work for standard toast events as well. 
 
Best Answer chosen by Yogendra Jangid
Yogendra JangidYogendra Jangid
@Deven, Finally I am able to go past this situation. We don't have any OOB LWC events that listen to standard show toast events but I have used a platform event that will get fired on record update/create and we can subscribe to that event in our LWC component and refresh the lightning-datatable once the save is commited and successful. To know more on how to do this please refer to my blog How to Refresh Lightning Datatable after triggering standard events(new/edit) in LWC (https://inevitableyogendra.blogspot.com/p/how-to-refesh-lightning-datatable-after.html). Please let me know if this resolves your problem too.

All Answers

Deven DamianoDeven Damiano

I am experiencing the same issue, were you able to find a solution for this?
Yogendra JangidYogendra Jangid
No Deven, I am still searching for the solution.
Yogendra JangidYogendra Jangid
@Deven, Finally I am able to go past this situation. We don't have any OOB LWC events that listen to standard show toast events but I have used a platform event that will get fired on record update/create and we can subscribe to that event in our LWC component and refresh the lightning-datatable once the save is commited and successful. To know more on how to do this please refer to my blog How to Refresh Lightning Datatable after triggering standard events(new/edit) in LWC (https://inevitableyogendra.blogspot.com/p/how-to-refesh-lightning-datatable-after.html). Please let me know if this resolves your problem too.
This was selected as the best answer