0

I am trying to delete the task on click of button. i am trying to execute apex code but its not hitting the apex method. Is am i doing wrong here or missed something. Thanks in Advance.

TaskDelete.cmp

<aura:component implements="flexipage:availableForAllPageTypes,force:hasRecordId"
                controller="TaskComponentController">

on click of button i am calling below js code to execute server side code.

    deleteTask: function(component, event) {
        var selectedItem = event.currentTarget;
        var recId = selectedItem.dataset.row;

        var action = component.get('c.deleteTask'); 
        action.setParams({
            "taskId" : selectedItem.dataset.row
        });
        action.setCallback(this, function(a){
            var state = a.getState(); // get the response state
            alert("Task Delete successfully.");
            if(state == 'SUCCESS') {
               // component.set('v.sObjList', a.getReturnValue());
            }
        });
        $A.enqueueAction(action);
}

apex code.

 @AuraEnabled public static Boolean deleteTask(String taskId){
    List<Task> record = Database.query('SELECT Id FROM TASK WHERE Id = \'' + taskId + '\'');
        try{
            delete record;
        } catch(Exception e) {
            throw new AuraHandledException('Exception occurred while deleting: ' + e.getMessage());
        }
        return true;
}
0

The controller method in Aura must not match the Apex method. This will cause problems. Rename either the controller method or Apex method so they are not both named deleteTask.

Use unique names for client-side and server-side actions in a component. A JavaScript function (client-side action) with the same name as an Apex method (server-side action ) can lead to hard-to-debug issues. In debug mode, the framework logs a browser console warning about the clashing client-side and server-side action names.

-- Documentation

1
  • Thanks..Its working now..
    – Adam lee
    May 20 '20 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.