In my code I am trying to update Account record. But the update is failed, how do i handle the error in my lightning component.

I tried this in helper:

var state = response.getState();

}else if(state=="ERROR"){
  var errors = response.getError();
// setting this error to on of the attribute of the component

NOTE: addError method @ field level in apex method cannot be handled in lightning. One of the limitations with respect to handling errors in lightning


Well, assuming that you have a reference to the component, then you would simply set the error to your attribute like this:

component.set("v.errAttribute", JSON.stringify(errors));

This is assuming that your errors attribute is a simple string, define something like:

<aura:attribute name="errAttribute" type="String" />

You could also extract the message from each error object and put that in an array of strings to render also:

<aura:attribute name="errorMessages" type="String[]" />


var errors = response.getError();
var errorMsgs = errors.map(function(error){
    return error.message;

Finally, you'd render them using an iteration:

    <aura:iteration items="{!v.errorMessages}" var="message">

Here is how I debug error

Code Snippet

 } else if (state === "ERROR") {
                var errors = response.getError();
                if (errors) {
                    if (errors[0] && errors[0].message) {
                        console.log("Error message: " + errors[0].message);
                } else {
                    console.log("Unknown error");
  • This I Tried but not working.Thank u so much for replying :) – Sahana Gowdar Sep 22 '16 at 7:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.