0

Problem - I have a DataTable with a Modify action that shows a lightning-record-edit-form when clicked. The user updates the lightning-record-edit-form and clicks the Submit button. The data is successfully modified behind the scenes, but the old values remain in the lightning-record-edit-form the next time I show it, unless I refresh the entire page. Is there a way to force a lightning-record-edit-form to refresh its data?

Markup

<lightning-record-edit-form object-api-name="Case__c"
    onsuccess={DetailSuccess} record-id={DetailRecordId}
    onsubmit={RecordSubmit} if:true={FormVisible}>

Scenario

{record-id} is set to X, X is updated, and then {record-id} is set to Y. Then I set the {record-id} back to X, but the old values of X appear instead of the modified values, until I refresh the entire page in the browser.

  • when you change X to Y, are the values changed? – salesforce-sas Sep 13 at 2:31
1

The problem is not because of cache. Initially (before changing values) when you change record-id the values in all input-fields will also reflect correct record values but when you change any of the inputs, it becomes dirty and will no longer reflect the values according to the changes in form (record-id) and to get the changes appropriately reflect the changes in record-id, you should use reset() method on inputs.

refreshValues() {
    const inputFields = this.template.querySelectorAll('lightning-input-field');
    if (inputFields) {
        inputFields.forEach((field) => {
            field.reset();
        });
    }
}

Invoke refreshValues() whenever you want to refresh the form - especially when you are changing record-id.

  • 1
    Thanks for your help. Unfortunately, this doesn't do the trick. Did you test this? – Mr. B Sep 13 at 17:22
  • yes i tested it, it will work and I cannot create it in playground, so can you post full code in question? – salesforce-sas Sep 13 at 17:33
  • Don't think I can, its too large and too sensitive. I posted another question that may help shine some light on what I'm asking (salesforce.stackexchange.com/questions/278091/…). – Mr. B Sep 13 at 19:13

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.