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.

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.

| improve this answer | |
  • 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 Sep 28 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 Sep 28 at 19:08
  • I understand now, thanks for providing explanation on this. Will check other options like the one you suggested above :) – Ertyq Sep 29 at 1:01

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.