1

I get this error on the bottom of the page when trying to show a toast message

This page has an error. You might just need to refresh it. Error in $A.getCallback() [$A.getEvt(...) is undefined] Callback failed: apex://StudentRegistrationController/ACTION$saveStudent Failing descriptor: {lightning:notificationsLibrary}

I did as the documentation stands for this:

Aura component:

<lightning:notificationsLibrary aura:id="notificationsLibrary"/>

Controller:

if(state === "SUCCESS") { 
    component.find('notificationsLibrary').showToast({
        "variant": "success",
        "title": "Contact Updated",
        "message": "Contact successfully updated"
    });
    window.setTimeout(
        $A.getCallback(function() {
            window.location.href = "/";
        }), 3000
    );
} else {
    console.error(JSON.stringify(response.getError()));
}

Won't work, even if I use:

var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
    "title": "Success!",
    "message": "The record has been updated successfully."
});
toastEvent.fire();

Happens the same.

Web console shows nothing, no error or warning.

What could it be? A bug from Salesforce maybe?

2 Answers 2

11

<lightning:notificationsLibrary> and force:showToast are both unsupported in the Lightning Out context, because they're handled by the Lightning Experience itself.

Note that the Component Library page for <lightning:notificationsLibrary> shows

Experience
Lightning Experience, Lightning Communities, Salesforce Mobile App

while force:showToast reads

This event is handled by the one.app container. It’s supported in Lightning Experience, Salesforce app, and Lightning communities.

You won't be able to make use of that built-in functionality without providing some implementation yourself.

2
  • Thank you David, one last question, which approach should I take to implement that? Thanks again
    – AjFmO
    Commented Apr 19, 2019 at 19:48
  • 1
    You'd need to be implementing whatever framework you want to use to display notifications, whether that looks like a Toast message or uses some other display mechanism. Paul's answer below has a link to how SLDS marks up notifications.
    – David Reed
    Commented Apr 20, 2019 at 12:02
3

Since this is one of the events not supported in Lightning Out, I would suggest adding some markup for the slds notification (https://www.lightningdesignsystem.com/components/notifications/) and have some conditional logic in the controller/helper which sets any messages then displays it.

You must log in to answer this question.

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