This question already has an answer here:

I am trying to implement custom action in lightning . The below controller code is to add two numbers and display using toast. It is however throwing the error :

Action failed: c:CustomAction$controller$clickAdd [Cannot read property 'setParams' of undefined]

The js controller code is:

clickAdd: function(component, event, helper) {
    // Get the values from the form
    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");
        "title": "Quick Add: " + n1 + " + " + n2,
        "message": "The total is: " + (n1 + n2) + "."

        // Close the action panel
var dismissActionPanel = $A.get("e.force:closeQuickAction");

The component code is :

<aura:component implements="force:lightningQuickAction">
    <!-- Very simple addition -->
<lightning:input type="number" name="myNumber" aura:id="num1" label="Number 1"/> +
    <lightning:input type="number" name="myNumber" aura:id="num2" label="Number 2"/>
    <lightning:button label="Add" onclick="{!c.clickAdd}"/>

I have copied this piece of code directly from the standard lightning guide.

marked as duplicate by glls, Vigneshwaran G, Brian Mansfield, Ratan Paul, Santanu Boral Sep 15 '17 at 17:09

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Do you call this Lightning component from your Lightning quick action? – Martin Lezer Sep 15 '17 at 11:43
  • Yes the component implements lightningQuickAction. – starhunter Sep 15 '17 at 12:34
  • Could you post your whole code? Because this is supposed to work. – Martin Lezer Sep 15 '17 at 12:47
  • Updated the post – starhunter Sep 15 '17 at 12:50
  • you must be trying to access it through Standalone app like /c/NameOfApp.app, isn't that the case? – Patlatus Sep 15 '17 at 12:52

There are several ways how you can access a lightning component.

  1. You can access lightning component from a standalone app accessed like /c/NameOfApp.app
  2. You can access it from a lightning tab
  3. You can access it from a lightning flexi page.
  4. You can access it from Visualforce.

Event e.force:showToast is available only for 2 and 3 case. And you must be trying to access it through Standalone app like /c/NameOfApp.app

  • Where does this comes from? I'm using the e.force:showToast event in my Lightning quick actions and this is working fine. – Martin Lezer Sep 15 '17 at 12:56
  • this question has actually already been asked salesforce.stackexchange.com/questions/149512/… salesforce.stackexchange.com/questions/149701/… – Patlatus Sep 15 '17 at 13:30
  • Yes but where did you find any documentation about the fact that force:showToast events are not working in a lightning quick action? – Martin Lezer Sep 15 '17 at 13:37
  • I mean that force:showToast are not available in standalone app or in lightning out for visualforce. I haven't tried whether this works or not in global actions or quick actions – Patlatus Sep 15 '17 at 14:14

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