1

I use lightning data service (lds) multiple times in different parts of my app. Each use of lds involves the same record. Do I need to manually reload it each time a change event is detected? So say in part A of my app, the record is updated, do I need to do acomponent.find('recordEditor').reloadRecord() in the change event for part B, C, D, etc that lds is used? Or does lds take care of that for me?

2

I haven't tried it out myself, but based on the below excerpt from trailhead, it doesn't seem that you need to force reload every time with the change (emphasis mine).

When LDS detects a record change, it notifies the components that use the record of the changes. If you don’t handle the change, the record is still updated, so any reference to the targetRecord or targetFields properties automatically shows up in your components. For every force:recordData component referencing the updated record, LDS does two things.

  • LDS notifies all other instances of force:recordData of the change by firing the recordUpdated event with the appropriate changeType and changedFields value.

  • It sets the targetRecord and targetFields attribute on each force:recordData to the new record value. If targetRecord or targetFields is referenced by any UI, this automatically triggers a rerender so that the UI displays the latest data.

Later it also mentions about Edit mode scenarios where the records are not updated automatically, which seems reasonable.

If force:recordData is in EDIT mode, targetRecord and targetFields are not automatically updated when the record changes. This is to avoid clobberin’ edits that are still in progress and to prevent unsaved changes from appearing in other components. Never fear, records can be refreshed manually by handling the recordUpdated event and calling the reloadRecord method.

| improve this answer | |
1

I would say the right time to reload LDS is on the callback method of any Apex calls that modified the record, or any other time you are somehow aware the record changed without the knowledge of the Lightning framework on the current page. A nice advantage of doing this is, it also refreshes the Details view on the record page. As a result, even in components that don't otherwise use LDS, I will include force:recordData and use it to refresh Details fields after Apex is finished with a change.

| improve this answer | |
  • Will calling recordReload in the callback record reload every instance that I'm using LDS, or just in the component that it is being used? – Tyler Zika Jan 25 '19 at 21:41
  • 1
    Every LDS instance of the same record in that browser tab. However I think it only reloads the fields specified even if other instances have other fields they're using. – Charles T Jan 26 '19 at 1:51
  • Have you ever reloaded LDS after an apex call that modifies the record? I can't seem to get it to work. – Tyler Zika Feb 5 '19 at 18:05
  • It's worked for me in the past year but I have not re-tested recently. – Charles T Feb 6 '19 at 1:44

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.