I'm having an issue where .setCallback is not functioning . Everytime I delete an account it doesn't work.
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.
accid
in quotes while setting the params.