Errors

To act when an error occurs, handle the recordUpdated event and handle the case where the changeType is “ERROR”.

Example

Declare that your component handles the recordUpdated event.
<force:recordData aura:id="forceRecord"
    recordId="{!v.recordId}"
    layoutType="FULL"
    targetRecord="{!v._record}"
    targetFields="{!v.simpleRecord}"
    targetError="{!v._error}"
    recordUpdated="{!c.recordUpdated}" />
Implement an action handler that handles the error.
({
  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 */ }
})
If an error occurs when the record begins to load, targetError is set to a localized error message. An error occurs if:
  • Input is invalid because of an invalid attribute value, or combination of attribute values. For example, an invalid recordId, or omitting both the layoutType and the fields attributes.
  • The record isn’t in the cache and the server is unreachable (offline).

If the record becomes inaccessible on the server, the recordUpdated event is fired with changeType set to "REMOVED." No error is set on targetError, since records becoming inaccessible is sometimes the expected outcome of an operation. For example, after lead convert the lead record becomes inaccessible.

Records can become inaccessible for the following reasons.
  • Record or entity sharing or visibility settings
  • Record or entity being deleted

When the record becomes inaccessible on the server, the record’s JavaScript object assigned to targetRecord is unchanged.