1

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
    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
    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
    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
    Jul 21, 2021 at 15:10

1 Answer 1

1

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
    Jul 21, 2021 at 17:52
  • @Damecek, why would that. You still need to type it and it still doesn't throw an error.
    – Schnaps
    Jun 10 at 6:32
  • I assumed that you are using some good IDE with intellisense. Like Intellij Idea with Illuminated Cloud 2 plugin.
    – Damecek
    Jun 11 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.