Quick Action API

lightning:quickActionAPI

Work with quick actions on record pages.

For Aura components only. For LWC quick actions, see the Lightning Web Components Developer Guide.

For Use In

Lightning Experience

A lightning:quickActionAPI component allows you to access methods for programmatically controlling quick actions on record pages.

For example, if you have a custom component that displays Knowledge articles, you can use the lightning:quickActionAPI component to attach and send a Knowledge article from your custom component via the Email quick action on the case record page.

To access the methods, create an instance of the lightning:quickActionAPI component inside your Lightning component or page and assign an aura:id attribute to it.

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

This example creates two buttons that interact with the Update Case quick action on a case record page in Lightning Experience.

1<aura:component implements="flexipage:availableForRecordHome" description="My Lightning Component">
2  <lightning:quickActionAPI aura:id="quickActionAPI" />
3  <div>
4    <lightning:button label="Select Update Case Action" onclick="{!c.selectUpdateCaseAction}" />
5    <lightning:button label="Update Case Status Field" onclick="{!c.updateCaseStatusAction}" />
6  </div>
7</aura:component>

The buttons call the following client-side controller.

1({
2  selectUpdateCaseAction: function (cmp, event, helper) {
3    var actionAPI = cmp.find("quickActionAPI");
4    var args = { actionName: "Case.UpdateCase" };
5    actionAPI
6      .selectAction(args)
7      .then(function (result) {
8        //Action selected; show data and set field values
9      })
10      .catch(function (e) {
11        if (e.errors) {
12          //If the specified action isn't found on the page, show an error message in the my component
13        }
14      });
15  },
16
17  updateCaseStatusAction: function (cmp, event, helper) {
18    var actionAPI = cmp.find("quickActionAPI");
19    var fields = {
20      Status: { value: "Closed" },
21      Subject: { value: "Sets by lightning:quickActionAPI component" },
22      accountName: { Id: accountId },
23    };
24    var args = { actionName: "Case.UpdateCase", entityName: "Case", targetFields: fields };
25    actionAPI
26      .setActionFieldValues(args)
27      .then(function () {
28        actionAPI.invokeAction(args);
29      })
30      .catch(function (e) {
31        console.error(e.errors);
32      });
33  },
34});

Usage Considerations 

The lightning:quickActionAPI component provides similar functionality to the Salesforce Classic Publisher JavaScript API. This component also supports utility pop-out.

To successfully use the Lightning Quick Action JavaScript APIs, make sure that you add the lightning:quickActionAPI component to a tab or location on the page that’s visible when the page loads. If the component isn’t visible when the page loads, the API isn’t used until the component is visible. For example, if you add the component to an Accordion component section that isn’t the default expanded one, the API is called only when a user opens that accordion section.

Methods 

This component supports the following methods. Most methods take only one argument, a JSON array of parameters. For more information on these methods, see the Publisher and Quick Action Developer Guide.

getAvailableActions()

A method that allows custom components to get a list of the available actions on a record page.

Returns a Promise. Success resolves to a response object. The Promise is rejected on error response. Common response object:

1success: true,
2        actions:
3            {actionName: "Case._LightningUpdateCase", recordId: "recordId", type: "QuickAction"}
4            {actionName: "FeedItem.TextPost", recordId: "recordId", type: "QuickAction"}
5            {actionName: "Case.LogACall", recordId: "recordId", type: "QuickAction"}
6            {actionName: "Case.SendEmail", recordId: "recordId", type: "QuickAction"}
7        errors: []

getAvailableActionFields({actionName})

A method that allows custom components to get a list of the available fields for a specific action on a record page.

Returns a Promise. Success resolves to a response object. The Promise is rejected on error response. Common response object:

1success: true,
2        fields:
3            {fieldName: "Subject", type: "textEnumLookup"}
4            {fieldName: "Description", type: "TextArea"}
5            {fieldName: "WhoId", type: "Lookup"},
6        errors: []

getCustomAction({actionName})

A method that allows custom components to get a custom quick action and pass data or messages to it.

  • actionName (string): The name of the quick action that you want to access.

Returns a Promise. Success resolves to a response object. The Promise is rejected on error response. Common response object:

1success: boolean,
2        customAction:             {
3                subscribe: function,
4                publish: function,
5                unsubscribe: function
6            },
7        ,
8        unavailableAction: boolean,
9        errors: []

Example:

1actionApi
2  .getCustomAction(args)
3  .then(function (customAction) {
4    if (customAction) {
5      customAction.subscribe(function (data) {
6        //Handle quick action message
7      });
8      customAction.publish({ message: "Hello Custom Action", param1: "This is a parameter" });
9    }
10  })
11  .catch(function (error) {
12    //We can't find that custom action.
13  });

getSelectedActions()

A method that allows custom components to get selected quick actions on a record page.

Returns a Promise. Success resolves to a response object. The Promise is rejected on error response. Common response object:

1success: boolean,
2        actions: [{actionName: "UpdateCase", recordId: "recordId"}],
3        errors: []

invokeAction({actionName})

A method that allows custom components to save or submit the quick action on a record page.

  • actionName (string): The name of the quick action that you want to submit.

Returns a Promise. Success resolves to true. The Promise is rejected on error response.

refresh()

Refreshes the current record page.

selectAction({actionName})

A method that allows custom components to select and focus on a quick action on a record page.

  • actionName (string): The name of the quick action that you want to select and set focus to.

Returns a Promise. Success resolves to true. The Promise is rejected on error response. Common response object:

1success: boolean,
2        unavailableAction: boolean,
3        actionName: string,
4        errors: []

setActionFieldValues({actionName, targetFields, parentFields, submitOnSuccess})

A method that allows custom components to select a quick action on a record page and then specify field values for that action. Because this method also selects the quick action, you don’t need to use the selectAction method. To submit the quick action updates, pass submitOnSuccess as true.

  • actionName (string): The name of the quick action that you want to select and set focus to.
  • parentFields (object): Optional. The fields that you want to update on the current record. For example, if you want to set field values on the Email quick action on the case record page, the case object is the parent record. You can use the parentFields parameter to change the value of the case record:
1parentFields:{Status: {value: "Closed"}, Subject: {value: "Case subject", insertType: "cursor"}}
  • targetFields (object): The fields that you want to update on the quick action. Use format:
1targetFields:{ToAddress: {value: "to@to.com"}, TextBody: {value: "my body", insertType: "cursor"}}
  • submitOnSuccess (boolean): Optional. Set to true if you want to save and submit the quick action after setting the field values. Default is false.

Returns a Promise. Success resolves to true. The Promise is rejected on error response. Common response object:

1success: boolean,
2        unavailableAction: boolean,
3        targetFieldErrors: [
4            {
5                Status: false,
6                Subject: false,
7            },
8        ],
9        errors: []

Attributes 

NameDescriptionTypeDefaultRequired
bodyThe body of the component. In markup, this is everything in the body of the tag.Aura.Component[]

Methods 

NameDescriptionArgument NameArgument TypeArgument Description
getAvailableActionFieldsGet a list of the available fields for a specific action on a record page.argumentsObjectArgument object with values for {actionName:'Case.UpdateCase'}.
getAvailableActionsGet a list of the available actions on a record page.
getCustomActionGet a custom quick action and pass data or messages to it.argumentsObjectArgument object with values for {actionName:'Case.UpdateCase'}.
getSelectedActionsGet the currently selected quick actions on a record page.
invokeActionSave or submit the quick action on a record page.argumentsObjectArgument object with values for {actionName:'Case.UpdateCase'}.
refreshRefresh the current record page.
selectActionSelect and focus on a quick action on a record page.argumentsObjectArgument object with values for actionName, entityName [optional].
setActionFieldValuesSelect a quick action on a record page and then specify field values for that action.argumentsObjectArgument object with values for {actionName:'Case.UpdateCase', targetFileds:[{name:'Status', value:'Closed', type:'Set'}], submitOnSuccess:true}.