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
Nikhil Shah 14Nikhil Shah 14 

Refresh LWC when a file is deleted.

Hi,
I have a custom LWC residing in record detail page. This LWC is displaying the files associated with the record. When user clicks on the file, I'm using NavigationMixin with 'standard__namedPage' and 'filePreview' to preview the file to the user. If the user deletes this file from the preview, then my LWC is not updating to remove the deleted file.

The LWC updates only when the user manually refreshes the page. But I see other standard related lists automatically refreshing when I delete the file from the preview because I see the spinner on each of those related lists.

When deleting a related file, how is it automatically refreshing the standard related lists on the record detail page? Which event/message do I need to subscribe to in my custom LWC to refresh itself too?

I searched everywhere, and everyone only talk about refresh the standard related lists automatically when custom component does something. But no one talks about the other way round - how to detect a change, or in my case a deletion of record in related list, in a custom LWC residing on the same record detail page?
Vinay MVinay M

Hi Nikhil.

  If ypu are using Apex to get the related files via Apex method in your LWC, you can use "refreshApex" and call it as soon as a record is deleted. Else if you have a method in LWC to call Apex (which gets the related files), you can call the same method again to get the updated list. 

 

https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.apex_result_caching

 

Thank you,

Vinay.