Tuesday, October 31, 2017

AuraHandledException

From Apex class:

 @AuraEnabled
    public static List<Account> fetchAccount() {
        throw new AuraHandledException('User-defined error');

    }

From client-side controller:

doInit: function(component, event, helper) {
        var action = component.get('c.fetchAccount');
        action.setParams({ firstName : cmp.get("v.firstName") });
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                component.set('v.Accounts', response.getReturnValue());
            }
            else if (component.isValid() && state === "ERROR") {
                console.log("Error Message: ", response.getError()[0].message);
            }
        });
        $A.enqueueAction(action);
    }


No comments:

Post a Comment