1

I get an error when doing multiple calls to getAvailableActionFields in a Promise.all().

The markup:

<aura:component implements="force:hasRecordId">
    <lightning:quickActionAPI aura:id="quickActionAPI"/>
</aura:component>

The controller:

component.find('quickActionAPI').getAvailableActions().then((result) => {
        const promises = result.actions.map(action => {
            return component.find('quickActionAPI').getAvailableActionFields({actionName: action.actionName});
        });
        return Promise.all(promises).then((results) => {
            results.forEach(res => console.log(res))
        });
    }).catch(error => console.log(error));

When I add this component to an opportunity page that has the quick actions New Task, New Event and Log a Call, I get the following responses:

The response I get from getAvailableActions() is an array with three quickActions:

actions: [
    {actionName: "Opportunity.NewOpportunityTask", recordId: "0061p00000gKO2BAAW", type: "QuickAction"},
    {actionName: "Opportunity.NewOpportunityEvent", recordId: "0061p00000gKO2BAAW", type: "QuickAction"},
    {actionName: "Opportunity.LogaCallOpportunity", recordId: "0061p00000gKO2BAAW", type: "QuickAction"}
]

The Promise.all() throws an exception with the following properties:

actionName: "Opportunity.NewOpportunityTask" 
errors: ["The action you specified isn’t available on the current record page."]
parentContext: null
success: false
targetName: undefined
unavailableAction: true

I believe the problem could be related to the parentContext being null.

Could this happen because of the way I invoke the second Promise, or could it be a limitation in the quickActionAPI?

1 Answer 1

1

I think it's because you didn't include the entityName as an argument in the getAvailableActionFields method. Try it again with the following code below where I added the one additional entityName argument to set the sObject API name.

component.find('quickActionAPI').getAvailableActions().then((result) => {
    const promises = result.actions.map(action => {
        return 
component.find('quickActionAPI').getAvailableActionFields({actionName: action.actionName, entityName:"Opportunity"});
    });
    return Promise.all(promises).then((results) => {
        results.forEach(res => console.log(res))
    });
}).catch(error => console.log(error));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy