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.


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

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'); 
            "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());

apex code.

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

1 Answer 1


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

  • Thanks..Its working now..
    – Adam lee
    Commented May 20, 2020 at 8:05

You must log in to answer this question.

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