0

I have a wire service that brings back a listing of records. I also have a "New" button on the LWC which uses a child component with a record-edit-form. I send an event that bubbles up to the parent after saving a new record and in the parent method I refresh apex. This works fine unless there are no records and I am adding the first record. The wire service does not get fired and the new record does not show up in my list until I refresh the page. Any suggestions on making this work when I'm creating my first record? thanks!!

1
  • Please provide some snippets with source code to clarify your problem. Jul 30, 2021 at 21:12

1 Answer 1

1

A cheat that should work is by passing a reactive parameter to your wired method. Lets say, the method which is decorated by wire take a parameter number of records rendered

export default class ReactiveWiredApexDemo extends LightningComponent {
  recordsRendered = 0;
  records;
  @wire(getRecords, { recordsRendering: '$recordsRendered' }
  getWiredRecords(response) {
    this.records = response;
    this.recordsRendered = response?.data?.length || 0;
  }

  handleRefresh(event) {
    // this will be called when child's event is received
    this.recordsRendered = 1 + this.recordsRendered;
  }
}

Because of the '$' symbol, every time the recordsRendered changes, getRecords will be called.

You must log in to answer this question.

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