0

I have a lightning component which is calling another apex class which in turn is calling anotehr apex class by creating its object.

The first class is already returning a value. However, I would also like the error message returned by class 2 and print in a toast message. Is this possible?

  • 1
    Do share some related code snippet as well, that helps in understanding the problem in more clear. – itzmukeshy7 Mar 24 '18 at 14:27
1

In your setCallback

In your JS controller, use below:

    samplecall.setCallback(this, function(Callresp) {
        if (Callresp.getState() === "SUCCESS") {
            helper.showToast('success', Callresp.getReturnValue() );
        } else if (status === "INCOMPLETE") {
            helper.showToast('error', Callresp.getReturnValue() );
        } else if (status === "ERROR") {
            helper.showToast('error', Callresp.getReturnValue() );
        }
    }

In your JS helper, use below:

showToast : function(type, message) {
    var toastEvent = $A.get("e.force:showToast");
    toastEvent.setParams({
        "type" : type, "key" : "action:announcement", "message": message
    });
    toastEvent.fire();
}

The above toast will show if your apex class has try catch block which returns AuraHandledException.

| improve this answer | |

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