10

Component

<aura:component implements="force:lightningQuickAction">
    <ui:inputNumber aura:id="num1"/> +
    <ui:inputNumber aura:id="num2"/>
    <br/>
    <ui:button label="Add" press="{!c.showToast}"/>
</aura:component>

Controller

  ({
        showToast : function(component, event, helper) {
        var n1 = component.find("num1").get("v.value");
        var n2 = component.find("num2").get("v.value");

        // Display the total in a "toast" status message

        var resultsToast = $A.get("e.force:showToast");
        resultsToast.setParams({
            "title": "Quick Add: " + n1 + " + " + n2,
            "message": "The total is: " + (n1 + n2) + "."
        });
        resultsToast.fire();

        // Close the action panel

        var dismissActionPanel = $A.get("e.force:closeQuickAction");
        dismissActionPanel.fire();
        }
    })

ERROR MESSAGE

This page has an error. You might just need to refresh it. Action failed: c$TestCheck1$controller$showToast [Cannot read property 'setParams' of undefined] Failing descriptor: {c$TestCheck1$controller$showToast}

7
  • 2
    how are you running the component? Is it inside a vf page?
    – Praveen
    Jan 16, 2017 at 17:06
  • No not in a vf in an aura:application I'm calling this component
    – david raj
    Jan 16, 2017 at 18:39
  • As Phil points standard force event like force:showToast will not work in lightning-out as well in Standalone App. It will work only in one.app container(sf1 or LEX)
    – Praveen
    Jan 17, 2017 at 3:49
  • Check Nordine's Post he got it when he previewed it i guess he created a lightning app and added it a tab and then might have previewed it let me do it and check
    – david raj
    Jan 17, 2017 at 4:14
  • 1
    I see it as a specific app where all the Lightning tabs are hosted.
    – Praveen
    Jan 17, 2017 at 4:58

3 Answers 3

7

If you're using Preview from Dev Console this won't work (or, as Praveen pointed out from Visualforce), you'd have to test it in lightning experience.

The documentation states:

This event is handled by the one.app container. It’s supported in Lightning Experience and Salesforce1 only.

I can only assume that Aura preview is not Lightning Experience (would think its to do with the full app framework not being loaded in preview).

0

When you try to launch the component via app , standard events (toast, navigateToSobject, etc) will be undefined.

var resultsToast = $A.get("e.force:showToast");

toastEvent will have "undefined " always.

Therefore launch your toastComponent in LEX via app builder or lightning quickaction or drag to detail page to check how it works.

1
0

It will work now, use below code

<aura:component implements="force:lightningQuickAction">
    <aura:dependency resource="markup://force:showToast" type="EVENT,COMPONENT" />
    <ui:inputNumber aura:id="num1"/> +
    <ui:inputNumber aura:id="num2"/>
    <br/>
    <ui:button label="Add" press="{!c.showToast}"/>
</aura:component>

You must log in to answer this question.

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