I need to show toast from LWC service component, but I don't have and won't have any instance of LWC component. That means no class which extends LightningElement.

This service will be used in Aura components. I just want to utilize ES6 features in the service.

How can I display toast in LWC without having LightningElement?

4 Answers 4


The only workaround I've thought of so far, is to wrap promise error in separate Error object with showToast(A) method and then in aura components do:

        TheAPIService.searchExternalCustomers({creditCardNumber: '4111111111111111'})
            .catch(error => error.showToast($A));

Without knowing much about whats going on in your ES6, you could have a callback function that you can pass from aura.


If LWC is a service, I don't suppose it should show any toast at all - it should remain framework agnostic. Why not dispatching an event from LWC that the aura component would listen to and display the toast in aura?

  • It's not framework agnostic. It's a service which provides interface for external callouts through apex in Aura and LWC. It will never possibly be framework agnotstic :) The goal is that it provides the default error handling (the toast), because that will be 99.9% of the cases, with possibility to overwrite it. Dec 13, 2019 at 7:29

Actually, I didn't use LightningElement because I couldn't find the methods on it. Turns out I was only missing @api annotation and that's it.

Still, Aura initializes before LWC so all my methods are completely useless in aura's "init" phase.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .