Refresh a record page from a Lightning web component

Fabien Taillon
Texeï
Published in
2 min readOct 7, 2020

--

A common use case

Lightning Data Service is a great tool allowing you to use the same cache as Lightning Experience, bringing better performances and less code to write.

Using Lightning Base Components like lightning-record-form or using out-of-the-box getRecord or createRecord methods will make record editing much easier. Thanks to the shared cache from Lightning Data Service, updating a record from your custom component will automatically update the standard record page, and vice versa.

Still, you’ll most likely end up at some point using Apex, if your use case is a little bit more complex than that, for instance involving a web service or multi-record editing.

Saving the current record from Apex have one drawback: it’s done outside of the eye of Lightning Data Service, and thus will not refresh the page correctly. Your component may display the correct updated value, but Salesforce’s standard record page will still display the old one.

So how do you ask to your record page to force update itself ? Well, Aura had a nice mechanism for it, force:refreshView. After the record was updated from Apex, you could just call it to ask Salesforce to refresh its own cache:

But alas, there was no such event in LWC 😩

I’ve seen several workarounds, from calling force:refreshView from LWC via a small hack, to saving a second time the record after…

> > > Click here to read the full article < < <

Click here to access all Texeï blog posts

--

--

Salesforce MVP | CTO @TexeiFrance | @ParisDUG Co-organizer | @FTDreamin Team