I have a custom component which goes on a record home page and displays certain related records. The selection logic is somewhat complex, so I cannot use Lightning Data Service; I am calling a custom apex controller. My method to retrieve the data is currently @wire
d. The component is build as a thin Aura wrapper around an LWC to allow me to raise certain force:*
events.
I'm having issues with changes to related records. There are a few scenarios, which probably have the same underlying cause (and hopefully same resolution). Let's say I'm showing certain related contacts on the account page, AND that the standard "Contacts" related list component is also visible. Here are some problem scenarios.
User clicks "New" button on standard Contacts related list and creates a new contact which meets the criteria to show on my custom component. On hitting save, the page navigates to the new Contact. The user then clicks the link back to the account. The standard Contacts related list shows the new contact, but my custom component doesn't show the new record. I'm sure this is because my controller method is
@wire
d and therefore cached. I could callrefreshApex
if I knew that I needed to. I could also un-wire it and call it imperatively during page load, but this feels un-LWC-like.User clicks "Delete" button on row in the standard Contacts related list, for a Contact which also appears in my custom component. The system displays a confirmation dialog, and the user confirms the deletion. The system deletes the record and displays a success toast. The standard Contacts related list refreshes to remove the deleted contact from the page, but my component does not. Again, I could call
refreshApex
if I knew that I needed to. Un-@wire
-ing the call to the controller wouldn't help here, as the page isn't being reloaded.
The force:refreshView
docs state:
We don’t recommend you to handle this event as it’s handled automatically by the app. To maintain the latest data on your page while reading and modifying your data, we recommend using force:recordData, which is built on Lightning Data Service.
As I stated above, LDS isn't an option in my case. "We don't recommend" implies that it is possible, so I tried adding a handler to my Aura wrapper (<aura:handler event="force:refreshView" action="{!c.handleRefresh}" />
) which simply logs to console, but it never fires.
Is there any way to be notified (via Aura- or LWC-available means) of these types of changes? These aren't changes originating from my own component, so I don't know when they occur.
Even if I could eliminate deletes/edits from other components (e.g., removing the standard related list component), I would still have an issue if the user navigates away, makes a change, and navigates back, if my apex controller's response is still cached. I tried to find a way to wire a method but force it to refresh on page navigation (using connectedCallback
), but of course any response saved in the component (to use when calling refreshApex
) is lost during navigation - so the apex response is cached from a prior page load, but the component has no way of knowing this.
<aura:handler event="force:refreshView" action="{!c.handleRefresh}" />
should have worked. As the record page does fire a internal refresh event to refresh its view. Can you show your code? As you have eliminated all options, I believe the only left option for you to go for is,Generic Event
, which you can use to refresh client view.aura:handler
code matches your example exactly. But I'm going to try @PrashantKashyap's answer later when I'm at my desk, and addisUrlAddressable
to see if it makes a difference.