[SalesForce] lightning callback not firing

Having in issue on my program running the setCallback. I have this one below which is working 100%:

.js

alert("Saving Comments!");       
        var saveCommentsAction = component.get("c.saveComments");
        saveCommentsAction.setParams({
            "comments" : comments
        });
        saveCommentsAction.setCallback(this, function(saveCommentsResponse) {
            var state = saveCommentsResponse.getState();
            console.log("callback response: "+state);
            if (state === "SUCCESS") {
                alert("Save Successful!");
                secData = saveCommentsResponse.getReturnValue();
                console.log(secData);
                component.set("v.SectionData",secData);
                component.set("v.sectionComments",secData.Comments__r); 
            } else {
                alert("Save failed due to the following error: " + saveCommentsResponse.getError()[0].message);
            }
        });
        $A.enqueueAction(saveCommentsAction);

.apxc

@AuraEnabled
    public static Audit_Section__c saveComments(List<SObject> comments) {
        system.debug('about to update: ***');
         List<Audit_Comment__c> commentsToUpdate = new List<Audit_Comment__c>();
        for (sObject commentObject : comments) {
            system.debug('asigning: ***');
            Audit_Comment__c comment = new Audit_Comment__c();
            comment.Id = commentObject.Id;
            comment.Comment__c = String.valueOf(commentObject.get('Comment__c'));
            comment.Audit_Section__c = String.valueOf(commentObject.get('Audit_Section__c'));
            commentsToUpdate.add(comment);
        }
        upsert commentsToUpdate;

        system.debug('**********'+commentsToUpdate[0].Audit_Section__c);
        Audit_Section__c section = xxx;
        return section;

    }

The Above code is working 100% and followed that principle to create the below but the below refuses to work.. Just does not get to calling the server side controller.

.js

var commentToDel;
        var btnClicked = event.getSource();
        var comments = component.get("v.sectionComments");        
        var thisCommentId = btnClicked.get("v.class");
        console.log("about to delete comment id: "+thisCommentId);
        for (var i in comments)
        {
            if (comments[i].Id == thisCommentId)
            {
                console.log("im equal: "+comments[i].Id);
                commentToDel = comments[i];                
            }
        }

var deleteCommentAction = component.get("c.deleteComment");
        deleteCommentAction.setParams({
            "comment" : commentToDel
        });
        console.log("Set Params +");
        deleteCommentAction.setCallback(this, function(Response) {
            Console.log("Begin callback");
            var state1 = Response.getState();
            console.log("callback response: "+state1);
            if (state1 === "SUCCESS") {

                alert("delete Successful!");
            } else {
                alert("Save failed due to the following error: " + Response.getError()[0].message);
            }
        });
        console.log("About to enqueue");
        $A.enqueueAction(deleteCommentAction);

.apxc

@AuraEnabled
    public static void deleteComment(Audit_Comment__c comment) {
        system.debug('************** Deleting');
        DELETE  [SELECT Id,Name FROM Audit_Comment__c WHERE Id = :comment.Id];             
    }

Console Out

about to delete comment id: a0D0Y000001qt19UAA
:37 im equal: a0D0Y000001qt19UAA
:46 Set Params +
:58 About to enqueue

Output of window.setTimeout(function(){console.log(deleteCommentAction‌​.getError())}, 5000);

 Objet:
    action: null
    >JP
    message: "Action failed: c:Audit_Section_Comments$controller$deleteComment [Cannot read property 'getSource' of undefined]"
    name:"TypeError"

My browser Log gets to "Set Params +" and "about to enqueue" But never enters the Callback as it doesnt display the response as well as my Dev Console Logs have no record of the action.

Please if this question is vague or needs more info just let me know, I am still new to this Form. Thanks in Advance.

Best Answer

According to this post, "a javascript method name in a component controller can never be the same name in an apex lightning controller":

Enqueued action not executed in Lightning Component

Just need to change the name of your javascript method to be different to the apex method

Related Topic