0

I'm having an issue where .setCallback is not functioning . Everytime I delete an account it doesn't work.

here is the image

Here is my attribute

<aura:attribute name="deleteholder" type="String" /> 

and here is my JS controller

deleteAcc: function(component, event, helper){
    var row= event.getParam("row");
    component.set("v.deleteholder", JSON.stringify(row.Id));     
    var deletethis = component.get("v.deleteholder");
    var action2 = component.get("c.deleteAcc");
    console.log(deletethis);
   action2.setParams({ 
        "accid": deletethis
    });
    alert("Test2");
    action2.setCallback(this, function(response) {
        var state = response.getState();
        alert(state);
        if (state === "SUCCESS") {
            alert("Success delete");
            var rows = component.get("v.acc");
            var rowIndex = rows.indexOf(row);
            rows.splice(rowIndex, 1);   
            component.set("v.acc", rows);
        }else{
            alert("Test callback");
        }
    });
    $A.enqueueAction(action2);

}

and here is my apex controller

@AuraEnabled
public static void deleteAcc(String accid){
    System.debug('Test in');
    try{
    Account acc = [SELECT Id FROM Account WHERE Id =: accid];
    delete acc;
    }catch(Exception eMessage){

        System.debug(eMessage.getMessage());
    }

}

Note: The issue is that the button is working fine , I think the issue is coming from the setParams or the setCallback. I don't have any idea what is wrong. I tried to re-do the codes but still having the same issue.

3
  • 2
    What is the error you are receiving? Also you don’t need to enclose accid in quotes while setting the params.
    – Jayant Das
    Commented Feb 13, 2019 at 3:28
  • Also, you’re swallowing the error message. Comment out the try-catch or re throw an AuraHandledException with the message to see what may be going on. Commented Feb 13, 2019 at 5:08
  • I figured out the culprit , it was the name of the function. deleteAcc <---- because var action2 = component.get("c.deleteAcc"); <--- is confused on which one he will call. I renamed it as deleteAcc2
    – rloreto
    Commented Feb 13, 2019 at 5:26

2 Answers 2

0

Hello instead of setting and then passing the attribute value you can pass row.Id as parameter

action2.setParams({ 
        "accid": row.Id
    });

and check whether row.Id is not undefined first

1
  • I did tried that but it is still not working.
    – rloreto
    Commented Feb 13, 2019 at 5:14
0

I was able to resolve it, there was a conflict on calling var action2 = component.get("c.deleteAcc"); because it is confused on which one it will execute thats why action2.setParams was not able to execute.

 deleteAcc2: function(component, event, helper){
            var rowId= event.getParam('row').Id;
            var action2 = component.get("c.deleteAcc");

       action2.setParams({ 
            "accountdelete": rowId
        });

        action2.setCallback(this, function(response) {
            var state = response.getState();
            alert(state);
            if (state === "SUCCESS") {
                alert("Success delete");
                var rows = component.get("v.acc");
                var rowIndex = rows.indexOf(row);
                rows.splice(rowIndex, 1);   
                component.set("v.acc", rows);
            }else{

            }
        });
        $A.enqueueAction(action2);

and the Apex Controller is

 @AuraEnabled
    public static void deleteAcc(String accountdelete){

          Account acc = [SELECT Id FROM Account WHERE Id =: accountdelete];
        try{

        delete acc;
        }catch(Exception eMessage){

            System.debug(eMessage.getMessage());
        }

    }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .