function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Andries.NeyensAndries.Neyens 

Calling a Quick Action from a custmo Lightning Component

I'm trying to launch a custom quick action from within a Lightning Component.
According the example given, it should work:

https://developer.salesforce.com/docs/atlas.en-us.case_feed_dev.meta/case_feed_dev/quickaction_api_getCustomAction.htm

And it all does work, if I add the highlight panel on the page that include the Quick action.
If you remove it from the page, the api returns:
 
{"targetName":"Contact","actionName":"Contact.Call","success":false,"parentContext":null}
Is there a way to call them, without having them on the lightning page?

 
Yogeshwar TailorYogeshwar Tailor
Hi Andries,

You can call custom action from quickaction api. Create quick action in contact named UpdateContact and try below code.

Component Code
<aura:component implements="lightning:actionOverride,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome">
	
    <lightning:quickActionAPI aura:id="quickActionAPI" />

    <lightning:button label="Update" onclick="{!c.updateContact }" />

</aura:component?




Controller Code
({
    updateContact : function(component, event, helper) {
        
		var actionAPI = component.find("quickActionAPI");
        var args = { actionName :"Contact.UpdateContact" }; // UpdateContact is the action on the contact object
        actionAPI.selectAction(args).then(function(result) {
            // Action selected; show data and set field values
        
        }).catch(function(e) {
            if (e.errors) {
                // If the specified action isn't found on the page, 
                // show an error message in the my component 
            }
    });

})

Thanks,
Yogesh

 
Andries.NeyensAndries.Neyens
Hi Yogesh,

did you tried this component on a lightning page ? It will work if you already have that action somewhere defined (like in a highlight component) on the page. But try it without that and you will receive:

"The action you specified isn’t available on the current record page."
 
SamHowleSamHowle
Hi @Andries,

You can only use the Quick Action API on a lightning record page. You also have to include the quick action on the page layout (mobile & lightning experience actions section) for it to be available for use. It's a pretty limited feature at the moment but has a lot of potential. The documentation is also pretty vague, at best, but if you have any questions let me know since I've got it working on my Account page.
Balaskandhan Bala KumaranBalaskandhan Bala Kumaran

Hi @SamHowle,

I am also getting the same error while trying to access the aviailable action fields for send Email action, Could you please tell me what's wrong in my code? Thanks.

Component Code:
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" description="My Lightning Component">
    <lightning:quickActionAPI aura:id="quickActionAPI" />
    <aura:attribute name="recordId" type="Id" />

    <div>
        <lightning:button label="Test Send Email" onclick="{!c.sendEmail}"/>
        <!--<lightning:button label="Update Case Status Field" onclick="{!c.updateCaseStatusAction}"/>-->
    </div>
</aura:component>

Controller Code:
({
    sendEmail : function(component, event, helper) {
        alert('Hello');
        var actionAPI = component.find("quickActionAPI");
        var recordId = component.get("v.recordId");
        var args = {actionName :"Account.SendEmail", entityName: "Account"};
        actionAPI.getAvailableActionFields(args).then(function(result){
            console.log('Available Fields are ', JSON.stringify(result));
        }).catch(function(e){
            if(e.errors){
                console.log('Action Field Log Errors are ',e.errors);
                console.error('Full error is ', JSON.stringify(e));
            }
        });
    }
})

SamHowleSamHowle
@Balaskandhan - it looks like you're using the wrong method. Do you need to set any field values or is it an automated action? If you look at the 2nd example on the Quick Action API developer page it shows an example that looks closer to what you want (invokeAction which would automatically fire off the quick action without any further input). See code below. Also, if you post the error / console results as well it would help troubleshoot. Btw if you use the code block formatting like below it's a bit easier to read.
 
updateCaseStatusAction : function( cmp, event, helper ) {
        var actionAPI = cmp.find("quickActionAPI");
        var fields = { Status : { value : "Closed"}, 
                       Subject : { value : "Sets by lightning:quickActionAPI component" }, 
                       accountName : { Id : "accountId" } };
        var args = { actionName : "Case.UpdateCase", 
                     entityName : "Case",
                     targetFields : fields };
        actionAPI.setActionFieldValues(args).then(function() {
            actionAPI.invokeAction(args);
        }).catch(function(e) {
            console.error(e.errors);
        });
    }
})

 
Mark Hartnady 23Mark Hartnady 23
THANK YOU! At first it didnt work, so I stuck in a toast event to show the actual error detail in your catch block. Turned out I was using the API name of the LightningQuickAction component rather than the name of the Action which binds the LightningQuickAction component to the object. After renaming it worked! What a huge time saver. Reusable components for the win!