Loading
×Sorry to interrupt
CSS Error
Aura Component

Quick Action API

  • This component allows you to access methods for programmatically controlling actions on record pages in Lightning Experience. This component requires API version 43.0 and later.

    Descriptor

    lightning:quickActionAPI

    Targets

    Lightning Experience

A lightning:quickActionAPI component allows you to access methods for programmatically controlling quick actions on record pages. This component is supported in Lightning Experience only.

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.

<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.

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

The buttons call the following client-side controller.

({ selectUpdateCaseAction : function( cmp, event, helper) { var actionAPI = cmp.find("quickActionAPI"); var args = {actionName: "Case.UpdateCase"}; 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 } }); }, 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); }); } })

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:

 success: true, actions: {actionName: "Case._LightningUpdateCase", recordId: "recordId", type: "QuickAction"} {actionName: "FeedItem.TextPost", recordId: "recordId", type: "QuickAction"} {actionName: "Case.LogACall", recordId: "recordId", type: "QuickAction"} {actionName: "Case.SendEmail", recordId: "recordId", type: "QuickAction"} 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:

 success: true, fields: {fieldName: "Subject", type: "textEnumLookup"} {fieldName: "Description", type: "TextArea"} {fieldName: "WhoId", type: "Lookup"}, 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:

 success: boolean, customAction: { subscribe: function, publish: function, unsubscribe: function }, , unavailableAction: boolean, errors: [] 

Example:

actionApi.getCustomAction(args).then(function(customAction) { if (customAction) { customAction.subscribe(function(data){ //Handle quick action message }); customAction.publish({message: "Hello Custom Action", param1: "This is a parameter"}); } }).catch(function(error) { //We can't find that custom action. }); 



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:

 success: boolean, actions: [{actionName: "UpdateCase", recordId: "recordId"}], 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:

 success: boolean, unavailableAction: boolean, actionName: string, 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:
     parentFields:{Status: {value: "Closed"}, Subject: {value: "Case subject", insertType: "cursor"}} 
  • targetFields (object): The fields that you want to update on the quick action. Use format:
     targetFields:{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:

 success: boolean, unavailableAction: boolean, targetFieldErrors: [ { Status: false, Subject: false, }, ], errors: [] 



Documentation
Specification