0

I want to toast the exception message when the callback is not succssful.

as per the guidelines here:- https://developer.salesforce.com/blogs/2017/09/error-handling-best-practices-lightning-apex.html

I have copied the handleErrors message in my helper js, below all other functions.

and I am calling it as below:-

var action= component.get("c.createAgrScope");
        var recordId = component.get("v.pageReference").state.recordId;
        action.setParams({"accIds": accId,
                          "agreementId": recordId});
        action.setCallback(this, function(a) {
            console.log('MVK Status of Action--->'+a.getState());
            if(a.getState() === 'SUCCESS'){
                this.somefunction(component,event);
            }else{
                var errorMsg = a.getError();
                var message = errorMsg[0].message;
                component.set("v.useSpinner", false);
                alert(message);
                handleErrors(errorMsg);

            } 

however, it is throwing me error that handleErrors is not defined.. can you please help.

The function is in helper itself, however I need to pass errors to it, as in the referenced link, it doesn't have component, event.. here is the definition:-

 handleErrors : function(errors) {
                    // Configure error toast
                    let toastParams = {
                        title: "Error",
                        message: "Unknown error", // Default error message
                        type: "error"
                    };
                    // Pass the error message if any
                    if (errors && Array.isArray(errors) && errors.length > 0) {
                        toastParams.message = errors[0].message;
                    }
                    // Fire error toast
                    let toastEvent = $A.get("e.force:showToast");
                    toastEvent.setParams(toastParams);
                    toastEvent.fire();
                }
1
  • Have you emebedded you app on a lightning page? Commented Apr 15, 2019 at 10:51

1 Answer 1

0

The error is coming because if you have defined handleErrors in helper file, then if you are invoking from controller then write -

helper.handleErrors(component, event, helper).

If you are invoking handleErrors method from helper itself, then write -

this.handleErrors(component, event, helper).
2
  • The function is in helper itself, however I need to pass errors to it, as in the referenced link, it doesn't have component, event.. edited question.
    – mvk1991
    Commented Apr 15, 2019 at 10:46
  • worked with this.handleErrors(errorMsg); my bad.. thanks.
    – mvk1991
    Commented Apr 15, 2019 at 10:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .