0

I have a Lightning Web Component that displays a list of records from a custom object. From that list, I have an action to open the standard edit page for a specific record. How can I refresh my list once the standard edit closed? Here is the code to open the standard edit. Thanks!

   //from Product actions List - Edit Product
editCurrentRecord(currentRow) {
    //set stayOnPage to navigate back to same page after edit
  this.stayOnPage = true;
  
    // assign record id to the record edit form
  this.currentRecordId = currentRow.Id;
    // Opens the Opportunity record modal
    // to edit a particular record.
  this[NavigationMixin.Navigate]({
    type: 'standard__objectPage',
    attributes: {
      recordId: currentRow.Id,
      objectApiName: 'opportunity_products__c',
      actionName: 'edit'
    },
    state:  {
      navigationLocation: 'RELATED_LIST'
    }
  });

1 Answer 1

1

I think you're looking for a RefreshView event. When the view changes in the app, a refresh event informs components that they may need to get fresh data.

The following code should work:

import { registerRefreshHandler, unregisterRefreshHandler } from 'lightning/refresh';
// ...
class MyComponent extends LightningElement {
  #refreshHandlerId;
  connectedCallback() {
    this.#refreshHandlerId = registerRefreshHandler(this, () => this.refreshHandler);
  }
  disconnectedCallback() {
    unregisterRefreshHandler(this.#refreshHandlerId);
  }
  refreshHandler() {
    refreshApex(this.tableData);
  }
}

I had to check the "Use Lightning Web Security for Lightning web components and Aura Components" under session settings to get SFDXfox's solution to work. thanks!

3
  • +1 Is that # at the beginning of refreshHandlerId syntactically correct? Nov 6, 2023 at 16:20
  • 1
    @RahulGawale Yes, they are private fields. Cannot be accessed outside the instance they are in, and must always be referenced through this.
    – sfdcfox
    Nov 6, 2023 at 20:14
  • I was not able to get this to work. It never calls the refreshHandler. I created a separate component just to test this with only this logic. It only updated properly when the component was on the same page as the standard layout that I update. The situation where I was trying to use this was opening a standard edit modal. After the edit on the modal, the lightning-datatable was not getting updated.
    – Frank
    Nov 14, 2023 at 14:37

You must log in to answer this question.

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