Ad Code

lwc quick action get record id

Lwc quick action

In this blog post, we see how to get a record id in the Salesforce lightning lwc quick action (Screen Action).

Create a lightning web component lwcQuickAction and add below-mentioned code in the respective files


<!-- sldsValidatorIgnore -->


  <lightning-quick-action-panel header="My action">

    <div>Record Id: {recordId}</div>

    <div class="slds-m-top_medium">

      <lightning-button label="Display record id in the console" variant="neutral" onclick={handeBtnClick}>



    <div slot="footer">

      <lightning-button variant="neutral" label="Cancel" onclick={closeAction}></lightning-button>

      <lightning-button variant="brand" label="Save" class="slds-m-left_x-small"></lightning-button>






import { api, LightningElement } from 'lwc';

import { CloseActionScreenEvent } from 'lightning/actions';

export default class LwcQuickAction extends LightningElement {

    @api recordId;


        console.log('Record id is ' + this.recordId);


    closeAction() {

        this.dispatchEvent(new CloseActionScreenEvent());





<?xml version="1.0" encoding="UTF-8"?>

<LightningComponentBundle xmlns="">







        <targetConfig targets="lightning__RecordAction">





The variable recordId decorated with @api annotation contains record id within the lightning web component.

Notice we have added recordId in the user interface (.html file), output looks like below

Lwc quick action get record id

And on click of a button, the record id is displayed in the browser console

Lwc quick action get record id in the browser console

If you get any issues or looking for something different, please post them in the comments section below.

In the upcoming article, we see another interesting topic covering lwc quick actions.

Until then…

Post a Comment