0

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?

6

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

  • Thank you David, one last question, which approach should I take to implement that? Thanks again – Adrian Apr 19 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 Apr 20 at 12:02
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.