function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Yogendra JangidYogendra Jangid 

Refresh LWC component on successful save of standard edit page navigation

I am using lightning datatable where there are two actions EDIT and DELETE. When I choose the EDIT option I am opening the standard edit navigation as follows.
<lightning-datatable 
     class="slds-max-medium-table_stacked"
     key-field="Id" 
     data={records.records}
     columns={records.columns}
     onrowaction={handleRowAction}
     hide-checkbox-column=true
     show-row-number-column=false>
</lightning-datatable>
on handleRowAction I am calling following for EDIT
 
handleRowAction(event) {
        this.actionName = event.detail.action.name.toUpperCase();
        const row = event.detail.row;
        switch (this.actionName) {
            case 'DELETE':
                this.selectedRecord = row;
                this.isDeleteModal = true;
                break;
            case 'EDIT':
                this.navigateToRecordEditPage(event, row.Id);
                break;
            default:
        }
    }

    navigateToRecordEditPage(event, recordId) {
        event.preventDefault();
        this[NavigationMixin.Navigate]({
            type: 'standard__recordPage',
            attributes: {
                recordId: recordId,
                objectApiName: this.records.relatedSobjectApiName,
                actionName: 'edit'
            }
        });
    }

this opens the standard modal and update the record but same is not reflected on datatable. Is there any way we can capture the save callback/event in LWC. I know we have option in aura as force:refreshView event, is there anything similar in lightning as well?

Note: I know this is possible if I use lightning-record-edit-form where I have full control on save and submit but I need this working for the standard navigatoin.
Best Answer chosen by Yogendra Jangid
Yogendra JangidYogendra Jangid
@Andrew, finally I am able to go past this situation. I have used a platform event that will get fired on record update/create and we can subscribe to that event in our LWC component and refresh the lightning-datatable once the save is commited and successful. To know more on how to do this please refer to my blog How to Refresh Lightning Datatable after triggering standard events(new/edit) in LWC (https://inevitableyogendra.blogspot.com/p/how-to-refesh-lightning-datatable-after.html" target="_blank). Please let me know if this resolved your problem too.

All Answers

ANUTEJANUTEJ (Salesforce Developers) 
Hi Yogendra,

Can you try checking the blog: https://www.axiom-consulting.co/blog/how-to-refresh-lighting-web-components-in-page-builder as it seems to have an implementation that could assist you in building your component:

>> https://www.axiom-consulting.co/blog/how-to-refresh-lighting-web-components-in-page-builder

I hope this helps and in case if this comes handy can you please choose this as the best answer so that it can be useful for others in the future.

Regards,
Anutej
Yogendra JangidYogendra Jangid
Hi Anutej, that also doesn't work. Actually when we are on home page(Account Page in this case) it will listen to that event, but it doesn't work or able to listen to when we update any child record(related list). Having said that, if I try updating related opportunity record, same event will not be listen by other child components but they will only listen to Account Edit page. 
Any way this implementation uses aura to capture the event(force:refreshView) and if I will embed my LWC component in my custom aura implementation, I can handle this easily. What I am expecting here if there is any OOTB functionality/event available that will allow me to catch and fire my refresh logic.
Andrew Porter 33Andrew Porter 33
@Yugendra Jangid did you manage to find a resolution to this problem?
Yogendra JangidYogendra Jangid
@Andrew, finally I am able to go past this situation. I have used a platform event that will get fired on record update/create and we can subscribe to that event in our LWC component and refresh the lightning-datatable once the save is commited and successful. To know more on how to do this please refer to my blog How to Refresh Lightning Datatable after triggering standard events(new/edit) in LWC (https://inevitableyogendra.blogspot.com/p/how-to-refesh-lightning-datatable-after.html" target="_blank). Please let me know if this resolved your problem too.
This was selected as the best answer