+ Start a Discussion
Ash asmanAsh asman 

Iam Getting this Error

$A.getCallback() [tate is not defined] Callback failed: apex://createleaddata/ACTION$saveLead Failing descriptor: {c:createleaddatacmp}
In this vf page Geeting error but record is creating
public  class createleaddata{
    @AuraEnabled
    
    public static void saveLead (Lead ledrec) {
    
        try{
            //Insert Lead Record
            upsert ledrec;
        }catch(DmlException e) {
            //get DML exception message
            throw new AuraHandledException(e.getMessage());
        }catch(Exception e){
            //get exception message
            throw new AuraHandledException(e.getMessage());
        }
        finally {
        }
    }
}



Controller
({
    createleadclick : function(component, event,helper) {
        //Getting the lead from page
        var newlec = component.get("v.newLead");
        //Assign server method to action variable
        var action = component.get("c.saveLead");
        //setting parameters for server method
        action.setParams({
            "ledrec": newlec
        });
        action.setCallback(this, function(response) {
            //Getting the response state
            var state = response.getState();
            //check if response is success
            console.log(state);
            var resultToast = $A.get("e.force:showToast");
            
            if (tate === "SUCCESS") {
                resultToast.setParams({"title": "Success!",
                                      "message":"The record has been created successfully."
                                     });
                
            }
            else if(state=="ERROR"){
                var errors=response.getError();
                if(erors){
                    if(errors[0]&& errors[0].message){
                        resultToast.setParams({"title":"Update Error",
                                               "message":"The update validation returned an error:"
                                               + errors[0].message
                                              });
                    }
                } else{
                    resultsToast.setParams({
                        "title":"Update Unknown Error",
                        "message":"The update returned an error:" +state
                    });
                }
            }else{
                resultsToast.setParams({
                    "title":"Update unknown Error",
                    "message": "The update returnde an error:" +state
                });
            }
            resultsToast.fire();
            $A.get("e.force:refreshView").fire();
            
            //This closes the Action Window
            var dismissActionPanel=$A.get("e.force:closeQuickAction");
            dismissActionPanel.fire();
        });
        
        
        
        
        // Adding the action variable to the global action queue
        $A.enqueueAction(action)
    }
})
 
Navin Selvaraj23Navin Selvaraj23
Hello Ash asman,

While you are comparing your state=="SUCCESS" in the if condition, there lies the error. Instead of "state" you have used "tate". That is the only spelling mistake.

PFB the highlighted line.
User-added image


Hope it helps. Please mark it as the best answer if this helps you.

Regards,
Navin S