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?
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
ortargetFields
properties automatically shows up in your components. For everyforce: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 appropriatechangeType
andchangedFields
value.It sets the
targetRecord
andtargetFields
attribute on eachforce:recordData
to the new record value. IftargetRecord
ortargetFields
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
andtargetFields
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 therecordUpdated
event and calling thereloadRecord
method.
-
I have the similar issue but I am not using the using the force:recordData but instead the recordEditForm salesforce.stackexchange.com/questions/321652/… can you please help what I am missing here – user81642 Oct 6 '20 at 18:22
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.
-
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 -
1Every 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