loader

Create quick action with LWC dynamically using apex & tooling aPI

Table of Contents

What's Quick Action?

In Salesforce, a Quick Action is a powerful feature that allows users to perform specific tasks or update records directly from a record’s detail page, a list view, or a related list. Quick Actions enable users to streamline their workflows and perform common actions without navigating to a separate page.

What can be achieved using Quick action?

Quick Actions can include a variety of functionalities, such as:

  1. Create Records: Users can quickly create new records, such as tasks, events, cases, or custom objects, directly from the parent record’s page.

  2. Update Records: Users can easily update specific fields on a record without editing the entire record. This is particularly useful for making quick updates to key information.

  3. Log a Call: Users can log call details, such as call duration and notes, for tracking interactions related to the record.

  4. Send Email: Users can compose and send emails related to the record. Email templates and attachments can be included.

  5. Post to Chatter: Users can post updates to Chatter feeds associated with the record, facilitating communication and collaboration.

  6. Custom Lightning Component: Quick Actions can also be built using Lightning Components, allowing for more complex custom functionality and integration.

Quick Actions can be added to different sections of the Salesforce interface, including:

  • Page Layouts: Added to the page layout of specific objects to appear on the record detail page.
  • List Views: Added to list views to perform actions on multiple selected records at once.
  • Related Lists: Added as buttons on related lists to perform actions on related records.

Users can access Quick Actions through buttons, links, or icons, depending on how they are configured. Overall, Quick Actions enhance user productivity by reducing the need to switch between different pages and providing a seamless way to perform common tasks in Salesforce.

Code to create quick action using tooling aPI

This type of requirement is quite common, especially when working on AppExchange app development. Often, the need arises to dynamically create a record quick action tailored to a Lightning Web Component (LWC). Here’s the code to accomplish this:


POST /services/data/v58.0/tooling/sobjects/QuickActionDefinition

Payload:

{"Metadata" : {
"label" : "Quick Action Label",
"optionsCreateFeedItem" : false,
"type" : "LightningWebComponent",
"lightningWebComponent" : "NameOfLWC"
},
"FullName" : "Account.QuickAction_DeveloperName"
}

Please make sure that LWC has target set for Quick Action otherwise an error will be thrown.

<?xml version=”1.0″ encoding=”UTF-8″ ?>
<LightningComponentBundle xmlns=”http://soap.sforce.com/2006/04/metadata”>
<apiVersion>52.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__RecordAction</target>
</targets>
<targetConfigs>
<targetConfig targets=”lightning__RecordAction”>
<actionType>Action</actionType>
</targetConfig>
</targetConfigs>
</LightningComponentBundle>

Need More Help?

If you require assistance with app development, the creation of quick actions, or the generation of any metadata through coding, please don’t hesitate to reach out to us. Our team of experts is dedicated to providing swift and effective support to meet your needs promptly. Feel free to contact us at your convenience.