I made a lwc to use as a quick action, but despite declaring an @api recordId property, when logging it in connectedCallback, I get undefined. This is the configuration:
<targets>
<target>lightning__RecordAction</target>
</targets>
<targetConfigs>
<targetConfig targets="lightning__RecordAction">
<actionType>ScreenAction</actionType>
</targetConfig>
Is the only way to pass the recordId, wrapping my lwc in an aura component? I thought, as lwc quick actions are only supported in record pages, that the recordId would be passed correctly.
Best Answer
I had to test this, but it seems there's two different behaviors for the different actionTypes.
recordId
is undefined inconnectedCallback
andrenderedCallback
unless you use it in your html. In that situation, onlyrenderedCallback
has the value ofrecordId
.Even something as simple as a conditional with
recordId
makes it accessible inrenderedCallback
.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 ActionsThis 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.