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
Michael MuchowMichael Muchow 

Refresh Lightning Web Component after Record update

Hi guys,
I have a Lightning Web Component, this component sits on the Record Page and gets the record id by import { getRecord } from 'lightning/uiRecord';

With this id and some Custom Metadata I query some data of this record by an apex class and give it back to the template to show it.

Now I want to refresh/call the apex class again to get the updated data if the record was updated.

How can I do this?

Khan AnasKhan Anas (Salesforce Developers) 
Hi Michael,

Greetings to you!

You can Refresh the Cache in LWC. Sometimes, you know that the cache is stale. If the cache is stale, the component needs fresh data. To query the server for updated data and refresh the cache, import and call the refreshApex(wiredProperty) function.
 
import { refreshApex } from '@salesforce/apex';
refreshApex(wiredProperty)

wiredProperty—A property or method annotated with @wire. To refresh a wired method, you must pass the argument the wired method receives (which is the wired value).

Please refer to the below link (scroll to Refresh the Cache section) which might help you further.

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

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Michael MuchowMichael Muchow
Hi,
thanks for your answer.
I know I can refresh the cache if I call the refreshApex() function.
My problem is I'm not sure how I can trigger this.

My LW Component does not update the record.
I want to refresh the apex call if someone updates the record via the normal record page.

Greetings Michael