4

Hopefully this is a simple typo somewhere that I just can't find, but I have a very simple LWC in a community to just get some record data, and the getRecord wire adapter isn't executing as recordId gets its data.

edit: To add some clarification, the wire adapter is firing once, when recordId is undefined, but is not being fired a second time when recordId gets set.

@api recordId;

wiredRecord;
@track record;
@wire(getRecord, { recordId: '$recordId', fields: recordFields})
handleWiredRecord(result){
    this.wiredRecord = result;
    console.log(result);
    const {error,data} = result;
    if (error){
        console.warn(error);
    } else if (data){
        console.log(data);
        this.record = data;
    }
}
connectedCallback() {
  console.log(this.recordId);
}

The output to the console is { data:undefined , error:undefined }, which is coming before the recordId output of the connectedCallback (which is working by the way)

I configured everything in the community and component correctly in that the recordId is coming through, however, the wire adapter runs before the recordId exists, and is not running again when it is populated.

Any help is appreciated.

console from above code:

{ data:undefined , error:undefined }
<recordId> // came through correctly
4
  • Does this answer your question? Get RecordId in LWC From Community Page
    – glls
    Commented Jul 21, 2021 at 14:34
  • did you try the adapter without function like this @wire(getRecord, { recordId: '$recordId', fields: recordFields}) wiredRecord; and then using just the this.wiredRecords.data
    – Damecek
    Commented Jul 21, 2021 at 14:34
  • @glls , I have the recordId making it into the component, the console.log in the connectedCallback hook returns the id, it just doesn't trigger an update of the wire adapter
    – stackasaur
    Commented Jul 21, 2021 at 15:09
  • @Damecek I have tried that as well as setting recordId via a custom getter/setter to change a local variable _recordId which I was then tracking $_recordId, but that also didn't cause any update when the value became available
    – stackasaur
    Commented Jul 21, 2021 at 15:10

2 Answers 2

4

The issue was in the list of fields names. I used a statically type list of names rather than references to the fields

The field API names are case-sensitive when called in the wire adapter and thus, a single typo in the name (a capital O when it should have been lowercase) caused the issue.

Note, this lead to no error messages from the wire adapter. The only indicator of it failing was it not running.

3
  • did u used this syntax import POSITION_LEVEL_FIELD from '@salesforce/schema/Position__c.Level__c';? this should avoid any spell mistakes.
    – Damecek
    Commented Jul 21, 2021 at 17:52
  • 1
    @Damecek, why would that. You still need to type it and it still doesn't throw an error.
    – Schnaps
    Commented Jun 10, 2022 at 6:32
  • I assumed that you are using some good IDE with intellisense. Like Intellij Idea with Illuminated Cloud 2 plugin.
    – Damecek
    Commented Jun 11, 2022 at 7:28
0

I'm not pretty sure that your problem has been resolved so... You can try add getter/setter to recordId, private variable should be decorated by @track decorator then use _recordId in getRecord. :)

1
  • Welcome to Salesforce Stack Exchange (SFSE)! While a helpful contribution is welcome, I still want to address your statement: "I'm not pretty sure that your problem has been resolved...." Just so you know for the future, a green check mark found under the arrows to the left side of an answer indicates that answer was accepted by the user who posted the original question. Acceptance of an answer almost always indicates the problem has been resolved. The other answer to this question has a green check mark.
    – Moonpie
    Commented Sep 11, 2022 at 2:51

You must log in to answer this question.

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