Sub topic 11
Creating the action and adding it to a page layout
This chapter assumes you can build an LWC with a template, a JavaScript class, and a js-meta.xml file. It also assumes you can deploy with Salesforce DX and that you know what a page layout is. The component exists and is exposed with lightning__RecordAction. It does nothing yet, because no one can click it. You need to create a quick action record in Setup, then place that action on a layout.
Create the action in Setup
A quick action is a metadata record that points at your component. Deploying the component does not create it.
- Open Setup and go to Object Manager.
- Select the object, for example Account.
- Choose Buttons, Links, and Actions, then click New Action.
- Set Action Type to Lightning Web Component.
- Pick your component in the Lightning Web Component list.
- Enter a Label, such as
Update Description. Salesforce suggests a Name from the label. The name becomes the API name, so choose it carefully. - Save.
The component list only shows components that are exposed with the lightning__RecordAction target. If yours is missing, check isExposed, the target, and whether the latest version was deployed.
The actionType in js-meta.xml (ScreenAction or Action) decides how the platform runs the component. You do not choose between them in Setup.
Add the action to a page layout
An action can exist on an object and still not appear. Layouts control what users see.
- In Object Manager, open Page Layouts and edit the layout.
- In the layout editor, find the Salesforce Mobile and Lightning Experience Actions section. If it shows default actions only, click the override link in the section header to customize it.
- Select Mobile & Lightning Actions in the palette.
- Drag your action into the section.
- Save the layout.
Open a record that uses that layout. The action appears in the highlights panel actions menu, or as a button if there is room.
Do it as metadata
Setup is fine for learning. For a team, keep the action in source control. A quick action is stored as Account.UpdateDescription.quickAction-meta.xml under quickActions.
<?xml version="1.0" encoding="UTF-8"?>
<QuickAction xmlns="http://soap.sforce.com/2006/04/metadata">
<label>Update Description</label>
<lightningWebComponent>updateDescription</lightningWebComponent>
<optionsCreateFeedItem>false</optionsCreateFeedItem>
<type>LightningWebComponent</type>
</QuickAction>The layout references the action by name in platformActionList, stored in the layout file. The simplest way to get that right is to retrieve the layout after editing it in Setup, then commit the result.
Common problems
| Symptom | Likely cause |
|---|---|
| Component is not in the Setup list | Not exposed, wrong target, or not deployed |
| Action exists but no button appears | Not added to the layout the user's profile uses |
| Layout editor shows no action palette | The section still uses the classic default list and needs the override |
| Old behavior after a code change | Browser cache. Hard refresh, then check the deployment succeeded |
For Lightning record pages built with App Builder, the highlights panel can also use the layout's actions. Check the component's action settings there if the layout change has no effect.
Exercise
You deployed an LWC with the lightning__RecordAction target and created a quick action for it on Account. Users still do not see the action on account records. What is the most likely missing step, and where do you fix it?
Show answer
The action has not been added to the page layout those users see. Edit the layout in Object Manager, add the action under Mobile & Lightning Actions in the actions section (overriding the default list if needed), and save. Also confirm the users' profile and record type use that layout.