I am new to Lightning and I would like to create a Custom Button (or maybe an Action) that just calls a Method in an Apex Class (in which I am sending some parameters).

Is this posible to do?


  • 1
    Hi i@jmarco, I would recommend you follow Trailheads in order to get familair with creating lightning components - amongst other things.
    – glls
    Mar 22, 2018 at 18:54

1 Answer 1


You need to create a lightning component that implements force:lightningQuickAction. After this you will be able to override your Action using this lightning component. You can program your client side controller to set a callback function, that would call your Apex class to perform some logical calculation. This is fairly simple and you can find numerous example on trailhead.

Edited: This code will rest in your JS controller:

var action = cmp.get("c.YourMethodName");
     param1: cmp.get("v.something1"),
     param2: cmp.get("v.something2")
action.setCallback(this, function(response) {
   if (response.state === "SUCCESS"){
       var serverResponse = response.getReturnValue();

Check out this link: https://trailhead.salesforce.com/modules/lex_dev_lc_basics/units/lex_dev_lc_basics_server

  • Thanks for the response, but how can I pass and receive the parameter to the lightning component?
    – jmarco
    Mar 23, 2018 at 9:57
  • Have edited my answer Mar 23, 2018 at 11:21
  • Thanks so much for the help! But my problem is that once I have the parameters on the component, I know how to send to the controller side, but how can I pass the parameters from the origin page to the component (For example I am on one determinate Opportunity, how can I send the Id of the oportunity to the component?)
    – jmarco
    Mar 23, 2018 at 12:20
  • When you override your Action button using the lightning component, lightning automatically adds an aura attribute called recordId. However, you need to add force:hasRecordId interface in the component. See this link developer.salesforce.com/docs/atlas.en-us.lightning.meta/… Mar 23, 2018 at 22:13

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