Newer Version Available
Handling 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:recordPreview aura:id="forceRecord"
2 recordId="{!v.recordId}"
3 layoutType="FULL"
4 targetRecord="{!v._record}"
5 targetError="{!v._error}"
6 recordUpdated="{!c.recordUpdated}" />Then 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})