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.
<force:recordData aura:id="forceRecord" recordId="{!v.recordId}" layoutType="FULL" targetRecord="{!v._record}" targetFields="{!v.simpleRecord}" targetError="{!v._error}" recordUpdated="{!c.recordUpdated}" />
({ recordUpdated: function(component, event, helper) { var changeType = event.getParams().changeType; if (changeType === "ERROR") { /* handle error; do this first! */ } else if (changeType === "LOADED") { /* handle record load */ } else if (changeType === "REMOVED") { /* handle record removal */ } else if (changeType === "CHANGED") { /* handle record change */ } })
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.
<force:recordData aura:id="forceRecord" recordId="{!v.recordId}" layoutType="FULL" targetRecord="{!v._record}" targetFields="{!v.simpleRecord}" targetError="{!v._error}" mode=”EDIT” recordUpdated="{!c.recordUpdated}" />
({ recordUpdated : function(component, event, helper) { var changeType = event.getParams().changeType; if (changeType === "ERROR") { /* handle error; do this first! */ } else if (changeType === "LOADED") { /* handle record load */ } else if (changeType === "REMOVED") { /* handle record removal */ } else if (changeType === "CHANGED") { /* handle record change; reloadRecord will cause you to lose your current record, including any changes you’ve made */ component.find("forceRecord").reloadRecord();} } })