4

I created a LWC for a custom object, exposed it to lightning__RecordPage and put it on the Lightning page for a related custom object. I added

@api 
recordId
@track 
subsidyId;

to the js controller, but it's not getting populated. Then in the connected callback I set the subsidyID. In order to be sure, I added this:

connectedCallback(){ 
        this.subsidyId = this.recordId;
        console.log('in connected callback, the record id: ', this.recordId);
}

and the result in the console is:

in connected callback, the record id:  undefined

Also, in the html I put the following:

 Subsidy Id: {subsidyId}

and it comes up empty.

The xml:

 <targets>
        <target>lightning__RecordPage</target>
        <target>lightning__AppPage</target>
    </targets>

What could I be doing wrong?

I noticed the following warning in the docs (here: https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.use_record_context)

IMPORTANT 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.

but I don't understand what that means. What is explicit record context?

1 Answer 1

4

Strange - I edited the page, and in the preview the id showed. I went back to the page and it shows. Go figure.

You must log in to answer this question.

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