0

I'am creating a lightning web component as quick action based on the Spring '21 release . I'm using an actionType of ScreenAction. My problem is that in connectedCallback the attribute recordId is still undefined. However, recordId has value when my button is clicked. I need the value of the recordId when the modal initializes to check the Opportunity Stage. Is there a way I can achieve this?

Here is my code:

HTML

<template>     


<lightning-quick-action-panel header="LWC Quick Action">
 
    {recordId}

</lightning-quick-action-panel>

JS

import { LightningElement, api } from 'lwc';


    export default class QuickActionTest extends LightningElement {
    
    @api recordId;
  
 
    connectedCallback(){
        console.log('connectedCallback');        
        console.log('recordId: ' + this.recordId);           
    }
}

Here is the output: Record ID has value in the modal: modal

And on the console log recordId is undefined. console

Thanks.

2
  • Please update your question with the code that you're trying
    – Raul
    May 19, 2021 at 10:08
  • As per the documentation the connectedCallback should be called after all API property values are initialized. If you still see this problem once you are working on a Summer '21 org, I suggest it is a bug that you should raise with Salesforce.
    – Phil W
    May 19, 2021 at 11:56

1 Answer 1

1

I had the same issue. I contacted Salesforce support since I didn't find anything in their documentation. Here is their answer :

The '@api recordId' will not be able to fetch the record Id directly here as the action type you are using is 'ScreenAction'.

You will have to fetch the recordId parameters from URL. Refer below .js code.

==================================== 
import { LightningElement, api,wire } from 'lwc'; 
import { CurrentPageReference } from 'lightning/navigation'; 

export default class QuickActionLWC extends LightningElement { 
currentPageReference = null; 
urlStateParameters = null; 

/* Params from Url */ 
recordId = null; 

@wire(CurrentPageReference) 
getStateParameters(currentPageReference) { 
if (currentPageReference) { 
this.urlStateParameters = currentPageReference.state; 
this.setParametersBasedOnUrl(); 
} 
} 

setParametersBasedOnUrl() { 
this.recordId = this.urlStateParameters.recordId || null; 
} 
connectedCallback(){ 
console.log(this.recordId); 
} 
} 
========================================== 

Here you can get the recordId from the URL.

1
  • Hi, I also reached out to Salesforce Support and they recommend to use Aura and LWC together to achieve this. Anyway I'll try this code. Thanks.
    – Duan
    Jun 29, 2021 at 12:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .