0

I'm trying to solve a problem with old data being saved. This component is on a detail page:

  • Open record
  • Amend one field and save
  • Use component to trigger a different field to update using force:recordData
  • Refresh the page
  • See that your first change is reverted

Am I doing this right to refresh the data? Here is my code:

<force:recordData aura:id="fieldUpdate"
                      layoutType="FULL"
                      recordId="{!v.recordId}"
                      targetFields="{!v.objectFields}"
                      targetError="{!v.errorMessage}"
                      mode="EDIT"/>

In the controller I am doing:

component.find("fieldUpdate").reloadRecord(true);
component.set("v.objectFields." + myFieldName, myFieldValue);
component.find("fieldUpdate").saveRecord($A.getCallback(function(saveResult) {
        if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
            console.log("Success!");
        } else if (saveResult.state === "INCOMPLETE") {
            thisRef.showErrorMessage("User is offline, device doesn't support drafts.");
        } else if (saveResult.state === "ERROR") {
            thisRef.showErrorMessage("There was a problem updating the Salesforce record: " + saveResult.error[0].message);
        } else {
            thisRef.showErrorMessage("Unknown problem, state: " +  saveResult.state + ', error: ' + saveResult.error[0].message);
        }
    }));

So when I call reloadRecord it doesn't actually get the change I just made in the UI. Am I doing something wrong?

1 Answer 1

0

I needed to handle the recordUpdated event and call reloadRecord in that handler.

Potentially this is because reloadRecord is only meant to run in that context and nowhere else.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .