lightning web component - quick action get record Id

A Quick action can invoke an LWC on record pages. 

There are two types of action: Screen & Headless. 


Regarding how to create quick actions, steps are as below:

1, configuration: 

    https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.use_quick_actions

2. create Quick action

3. Setup->Account->Botton,Links, and Actions->new Action-> Action Type: Lightning Web Component.

 

RecordId:

In Headless, we can easily get recordId from invoke method. 


import { LightningElement, api } from "lwc";

export default class HeadlessSimple extends LightningElement {

    @api recordId

    @api invoke() {

console.log(this.recorId); }

}



However, In screen action, we can't get recordId. now mater

connectCallBack() renderedCallBack(). There are severl way to get

recordId.


1. using setter, getter.

    _recordId;

    @api set recordId(value) {
// get contacts
this._recordId = value;
...
}

    get rcordId(){
    return this._recodId;
}


2. get in the renderedCallBack();

    this way, we muct use the recordId in html file. like:

<div style="display: none">{recordId}</div>

    and in js file:


@recordId;
isFirst = true;
renderedCallback() {
    if(this.recorId && isFirst){
    ...

    isFirst = false;
    }
    
}


3. using CurrentPageReference to get recordId.


Comments

Popular posts from this blog

Salesforce Digital Experience Cloud 2 ---> Sharing Data with partnier

Salesforce Digital Experience Cloud -- one