Newer Version Available
Record Changes
To perform tasks beyond rerendering the record when the record changes, handle the
recordUpdated event. You can handle record loaded,
updated, and deleted changes, applying different actions to each change type.
If a component performs logic that is record data specific, it must run that logic again when the record changes. A common example is a business process in which the actions that apply to a record change depending on the record’s values. For example, different actions apply to opportunities at different stages of the sales cycle.
Example
Declare that your component handles the recordUpdated
event.
1<force:recordData aura:id="forceRecord"
2 recordId="{!v.recordId}"
3 layoutType="FULL"
4 targetRecord="{!v._record}"
5 targetFields="{!v.simpleRecord}"
6 targetError="{!v._error}"
7 recordUpdated="{!c.recordUpdated}" />Implement an action handler that handles the
change.
1({
2 recordUpdated: function(component, event, helper) {
3
4 var changeType = event.getParams().changeType;
5
6 if (changeType === "ERROR") { /* handle error; do this first! */ }
7 else if (changeType === "LOADED") { /* handle record load */ }
8 else if (changeType === "REMOVED") { /* handle record removal */ }
9 else if (changeType === "CHANGED") { /* handle record change */ }
10})When loading a record in edit mode, the record is not automatically updated to prevent edits currently in progress from being overwritten. To update the record, use the reloadRecord method in the action handler.
1<force:recordData aura:id="forceRecord"
2 recordId="{!v.recordId}"
3 layoutType="FULL"
4 targetRecord="{!v._record}"
5 targetFields="{!v.simpleRecord}"
6 targetError="{!v._error}"
7 mode=”EDIT”
8 recordUpdated="{!c.recordUpdated}" />1({
2 recordUpdated : function(component, event, helper) {
3
4 var changeType = event.getParams().changeType;
5
6 if (changeType === "ERROR") { /* handle error; do this first! */ }
7 else if (changeType === "LOADED") { /* handle record load */ }
8 else if (changeType === "REMOVED") { /* handle record removal */ }
9 else if (changeType === "CHANGED") {
10 /* handle record change; reloadRecord will cause you to lose your current record, including any changes you’ve made */
11 component.find("forceRecord").reloadRecord();}
12 }
13})