0

I have a component that is just filling out a lightning-datatable. When opened on a record page, it fills with data specific to that record. This is working as expected. But I would also like to have it fill with all currently active data created by the current user (not record-specific) if it is opened on a home page.

Here is what I am using for when the recordId exists:

    @wire(getList,{accId:'$recordId'})
    list(result){
        morestuff;
    }

But when the recordId is undefined, the getList method never runs. Is there a way to easily go about this? Basically the getList function just has a different SOQL query returned based on whether the recordId exists or not. But the function never runs if it doesn't exist (understandable, per the important note in the documentation)

1 Answer 1

1

You can use a getter/setter to insert a null value:

_recordId;
@api set recordId(value) {
  this._recordId = value || null;
}
get recordId() {
  return this._recordId;
}

_recordId is just a notation I use for backing/internal variables, you can name it whatever you like. You might need to adjust your wire method to for reactivity to work, as the documentation isn't clear on that.

1
  • Much more elegant than the workaround I had come up with! I just had to change the "= value || null" part because that seemed to accept undefined as a value and it never came out as null.
    – Mplax
    Commented May 19, 2022 at 15:28

You must log in to answer this question.

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