0

Context

I have a custom Lightning Web Component that allows modification of multiple records inside of modal. Once a record is updated, I reload that same record-id, but the old data shows up instead of the new data. After thorough research, I have concluded that the Lightning Data Service is at fault here. It is caching the data in the built-in ViewState most likely. The only way to get a data refresh is by refreshing the entire web page. I found multiple articles that explain how to turn off Secure and Persistent Browser Caching, but this is an unacceptable solution, as the entire Organization will take a performance hit, to support my little Lightning Web Component. Also salesforce insists that you don't do it production:

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/debug_disable_caching.htm

Question

How do I invalidate or send a ChangeNotify Event to the Lightning Data Service (in the context of Lightning Web Components), so my lightning-record-edit-form shows the updated data, instead of the old data (without refreshing the entire web page of course)?

Specific Screenshot

enter image description here In the screenshot above (sorry for the low res.), the 'Modify Existing Entry' section is loaded with the respective row details from the DataTable below when the user clicks the 'Modify' action seen below. The 'Modify Existing Entry' section visibility and record-id depend on the HTML attributes as follows:

<lightning-record-edit-form object-api-name="Case_Detail__c"
 record-id={ModifyRMADetailRecordId}
 if:true={ModifyRMADetailFormVisible} ... >
 ...
</lightning-record-edit-form>

The problem is when the user clicks the 'Modify' action the second time for a given row (image above shows this scenario). Instead of loading the updated values for Serial Number, Manufacturer and Model, it loads the previous values (caching problem). As mentioned above, when I turn off the 'Enable secure and persistent browser caching to improve performance' feature in Session Settings, the caching problem goes away. However, this is not an acceptable resolution for the organization (per management - already asked). What I essentially want to do is disable 'Enable secure and persistent browser caching to improve performance' selectively in the context of my Lightning Web Component.

  • It is not clear how exactly its loading from cache. for example, you can use either temple if:true (conditional rendering) or just slds-hide just to hide the modal. Also there are many other factors, you can either post the code or show gif in question so that we understand what is happening. As of now question is too broad – salesforce-sas Sep 14 at 2:33
  • @salesforce-sas Thanks for your response. I have updated the question with a screenshot and outlined the specifics of my issue. Thanks again for taking the time to assist me. – Mr. B Sep 16 at 15:13
  • have you tried firing refreshview event post your operations?developer.salesforce.com/docs/component-library/bundle/… – Rao Sep 16 at 17:07
  • @Rao I've seen the approach you are talking about but cannot find a this.dispatchEvent LWC (Lightning Web Component) equivalent. Is there a way to do this in LWC. If so can you answer the question with how to incorporate it into an LWC? – Mr. B Sep 16 at 18:38
  • Oops I did not see lwc was assuming lightning – Rao Sep 16 at 22:15
0

Not invalidating the cache ended up being a known bug per salesforce support request. I had to fall back to Apex. My code looks like:

import LookupIt from 
'@salesforce/apex/CaseLookupController.LookupIt';
import DeleteIt from 
'@salesforce/apex/CaseLookupController.DeleteIt';
import StoreIt from 
'@salesforce/apex/CaseLookupController.StoreIt';

Then for example for my onsubmit button I have:

// Prevent submit
evt.preventDefault();

// Invoke store Apex
StoreIt({identity: this.LookupItResult.Id, storageModel: evt.details.fields})
  .then(result => { ... }
  .catch(error => { console.log(error) });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.