+ Start a Discussion
Shreya KakadeShreya Kakade 

how to add toast success message in lightning component

Hello Everyone,

I am trying to add the Toast message to the lightning Component But its not working here is the my code of the Function.

deteteQuestion : function(component, event, helper){
        var action = component.get("c.delSlctRec");
        var idx = event.target.id;
        action.setParams({ "slctRec" : idx});
        var toastEvent = $A.get("e.force:showToast");
                        title: "Success!",
                        message: "Congrats, it works!",
                        type: "success"
        //var result = confirm("Are you sure you want to delete?");
       // if(toastEvent) {
            action.setCallback(this, function(response){
                var state =  response.getState();
                if(state === "SUCCESS")
                    //document.getElementById("msg").innerHTML = "Record deleted successfully";
                    //alert('Successfully Deleted.');
                    // window.location.reload();
                }else if (state=="ERROR") {
       // }
Veena Sundara-HeraguVeena Sundara-Heragu
The JSON argument for toastEvent.setParams needs quotes around title, message and type like this:

                        "title": "Success!",
                        "message": "Congrats, it works!",
                        "type": "success"