[SalesForce] Cannot Set @api Property For LWC Component In Lightning Flow

I have a LWC component, that has a very simple public property:

@api recordId;

And I have a LWC config, that exposes this public property to the Flow Builder

<targets>
<target>lightning__FlowScreen</target>
</targets>
<targetConfigs>
    <targetConfig targets="lightning__FlowScreen">
        <property name="recordId" type="String" label="Record Id" default="{!recordId}" required="true"></property>
    </targetConfig>
</targetConfigs>

In my flow, there is a standard variable recordId, and when I put my LWC in one of these screen actions, I can even select the "Record Id" and fill it with {!recordId}. But: recordId (in the LWC) never gets populated. It is populated in the Flow. At least it seems that way, if I output {!recordId} in a "display text"

Why?

Best Answer

I had a similar scenario where I wasn't able to the record Id passed into my component in a flow, but it worked on a record page. I tried using the result of a query {!getOpportunity.Id} rather than {!recordId} even though they would be identical and that worked. Perhaps the reason has something to do with this:

The recordId is set only when you place or invoke the component in an explicit record context. In all other cases, the recordId isn’t set, and your component shouldn’t depend on it.

From Developer.Salesforce.com: Make a Component Aware of Its Record Context

Related Topic