I had to test this, but it seems there's two different behaviors for the different actionTypes.
- ScreenAction
recordId
is undefined in connectedCallback
and renderedCallback
unless you use it in your html. In that situation, only renderedCallback
has the value of recordId
.
Even something as simple as a conditional with recordId
makes it accessible in renderedCallback
.
<template>
<template if:true={recordId}>
test
</template>
</template>
import { LightningElement, api } from 'lwc';
export default class Testing extends LightningElement {
@api recordId;
connectedCallback() {
console.log('connected===============');
console.log(this.recordId + ' is null');
}
renderedCallback() {
console.log('rendered------------');
console.log(this.recordId + ' is provided');
}
}
If the variable is not in the html template, it's not provided to you without extra changes on your part - you can look at the other answer for using CurrentPageReference
or use getRecord as shown in lwc-recipes and Create Screen Quick Actions
@wire(getRecord, { recordId: '$recordId', fields: FIELDS })
- Action
This is a headless action from the quick action (no screen). This has the value provided to it in an invoke
call as noted in documentation since there's no rendering going on.
import { LightningElement, api } from "lwc";
declare default class HeadlessSimple extends LightningElement {
@api recordId;
@api invoke() {
console.log(this.recordId);
}
}