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?

closed as too broad by glls, David Reed, DavidSchach, Raul, sfdcfox Mar 25 '18 at 16:16

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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

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");
        "type" : type, "key" : "action:announcement", "message": message

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

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