0

In my LWC I have a few @api properties that are wired to a function that returns data from an Apex controller. However, one of these would be null be default. It seems that, as long as this property is null, the wire function is not firing.

import { LightningElement, api, track, wire } from 'lwc';
import getData from '@salesforce/apex/LightningController_MyController.getData';

export default class MyComponent extends LightningElement {
    @api recordId;
    @api relationshipName;
    @api filter;
    rows;

    @wire(getData, {recordId: '$recordId', relationshipName: '$relationshipName', filter: '$filter'})
    wiredData({error, data}) {
        if(data) {
            // do things
        } else if (error) {
            console.log(error);
        }
    }
}

As long as my filter property is left empty in, say, the Page Builder, the function is not firing. Once I do fill in that property, it does fire.

I assume that, as it is reactive, it awaits the property to be assigned a value. Is this correct, and more importantly, how would I allow for @api-decorated wire arguments to be left empty?

3
  • 3
    There's a high chance that the wired function is evaluated and the Apex is just returning null. Could you also include your Apex code in your question?
    – Naga
    Feb 16, 2021 at 22:23
  • 2
    I built an app, and have confirmed that even if you pass in an undefined value, you'll still get a wire call and output. Make sure your method always returns a non-null value.
    – sfdcfox
    Feb 17, 2021 at 2:52
  • Strange, I see no logs in the developer console. The above is just a simplification of my actual component so I might be missing something there. Thanks guys!
    – Steven.B
    Feb 17, 2021 at 10:29

1 Answer 1

0

We are seeing the same behavior with a Lightning Web Component in a flow, in that the reactive variables included in the wire definition simply will not fire in the event a value is null. This is specifically when trying to fire a refreshApex action. Eventually, we just ended up setting a text value of 'null' in the connected callback if the input parameter was null to allow the wire behavior to function.

if (this.inputValues === null || this.inputValues === undefined) this.inputValues = 'nullTextString:noValue';

You must log in to answer this question.

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