Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
Record Changes
If a component performs logic that’s specific to the record data, 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
1<force:recordData aura:id="forceRecord"
2 recordId="{!v.recordId}"
3 fields="Name,Title,Email"
4 targetRecord="{!v._record}"
5 targetFields="{!v.simpleRecord}"
6 targetError="{!v._error}"
7 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") { /* handle record change */ }
10})When loading a record in edit mode, the record isn’t 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 fields="Name,Title,Email"
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})