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();
}