1

I would like to use lightning:quickActionAPI's getSelectedActions() method in a lightning component (aura) to get the action name (custom/standard actions on an object) that is currently selected on a record page. I couldn't find any resource specific to this getSelectedActions() method though there are examples for other methods in quickActionAPI.

I found the documentation on this method here - https://developer.salesforce.com/docs/component-library/bundle/lightning:quickActionAPI/documentation but not sure how to construct this method.

Can someone please share an example of how we could use this specific method (getSelectedActions()) to get the action name?

Thank you!

0
0

I tried the below code and it worked as expected.

Include this in the Component(.cmp):

<lightning:quickActionAPI aura:id="quickActionAPI"/>

Controller code(.js):

let actionApi = component.find("quickActionAPI");
actionApi.getSelectedActions().then(function(result){
    let actionNameValue = result.actions[0].actionName;

    //If my quick action api name is 'Custom_Edit', this returns the 
    //action name as CustomObject__c.Custom_Edit
    console.log('Action name with object api name is - '+actionNameValue);

     //To Split and get just the action api name, do the below.
    if(actionNameValue.includes('.')) {             
        let getActionName = actionNameValue.split('.')[1];
        //This returns value as 'Cutom_Edit'
        console.log('getActionName - '+getActionName);
    }

}).catch(function(error){
    console.log('Errors - '+error.errors);
});

Note: This will work only on record page actions. If you want to use it on an object home tab (to get value of 'New' button), this wont work.

0

Here is a demo for you:

actionApi.getSelectedActions().then((selectedActions)=>{
  if (selectedActions && selectedActions.length > 0) {
      selectedActions.forEach(action=>{
        console.log(action.Name);
      })
    }
  }).catch(function(error) {
    console.log(error);
  });
       

Looking at the examples prior to this, selected actions is the result that gets passed to the handler. It is an array of objects, allowing iteration to get the object names.

2
  • Thank you Caspar. I will give that a try to learn how that works. I have also posted the code that worked for me :) – Meena Apr 8 at 18:02
  • I missed out a . between action and Name. Fixed. Your version will work, but if there are no selected actions, it will fail with a null pointer error. – Caspar Harmer Apr 8 at 18:36

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.