1

I created and displayed a custom list button in standard Lead list view. This references a Visualforce page. Clicking this button makes an action, and there's nothing wrong with the results in the backend so far.

My problem is that upon success of the operation, a toast that will supposedly display a success message is not displaying at all. The alert message is displaying, though. But upon dismissing this alert box, following error appears:

Error in $A.getCallback() [Cannot read property 'setParams' of undefined] Callback failed

Meanwhile, below are the current codes I have:

lead.app

    <aura:application access="GLOBAL" extends="ltng:outApp" >
        <c:lead />
    </aura:application>

lead.cmp

    <aura:component controller="MyClass" implements="force:lightningQuickAction">
       <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    </aura:component>

lead.js

    ({

    "doInit" : function(cmp) {
      
        var action = cmp.get("c.runClass");
   
        action.setCallback(this, function(response) {
            var state = response.getState();
            var title = '';
            var type = '';
            var message = '';
            if (state === "SUCCESS") {
                 
                alert("Success from server: " + response.getReturnValue());
                title = 'Success';
                type = 'success'; 
                message = 'Operation is successful';
            }
            else if (state === "INCOMPLETE") {
                // do something
            }
            else if (state === "ERROR") {
                var errors = response.getError();
                if (errors) {
                    if (errors[0] && errors[0].message) {
                        console.log("Error message: " + 
                                 errors[0].message);
                        alert("Error from server:" + errors[0].message);
                    }
                } else {
                    console.log("Unknown error");
                }
            }
            
            var toastEvent = $A.get("e.force:showToast");
            toastEvent.setParams({
                "title": title,
                "type": type,
                "message": message
            });
            toastEvent.fire();
            
        });

        $A.enqueueAction(action);
    }
    
    })

Hoping anyone can lead me to the right direction.

1 Answer 1

2

Toasts are not supported outside of Lightning Experience, communities, and the mobile app. You will need to build your own toast component. The Lightning Strike library by Appiphony is one such example that includes a toast component; you can look on github and elsewhere for other examples.

3
  • I am using Salesforce Lightning interface by the way. I used Visualforce which references a Lightning component so it could appear in standard Lightning UI list view.
    – Ertyq
    Commented Sep 28, 2020 at 17:51
  • 1
    @Ertyq Lightning Out is not within the Lightning Experience, even in a Visualforce page placed within Lightning Experience. Visualforce doesn't have access to the Lightning Experience runtime, which is why Lightning Out is required to begin with. Further, events created within this container can't make it to the Lightning Experience runtime. As such, you need to either create your own toast, or you need to have a helper component on the outside (e.g. a Utility Bar Component) to actually display the toast.
    – sfdcfox
    Commented Sep 28, 2020 at 19:08
  • I understand now, thanks for providing explanation on this. Will check other options like the one you suggested above :)
    – Ertyq
    Commented Sep 29, 2020 at 1:01

You must log in to answer this question.

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