0

I am adjusting my salesforce Application to include Lightning Experience compatibility. One of my application functionalities is to delete records from custom objects by pressing a button called Delete Data. The problem i face is that when i press the button the page freezes without deleting any records. Below are the code for my component and controller as well as my Apex Class method. Any help would be much appreciated.

Component Snippet

<aura:component controller="LightningComponentController" implements="force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordId" access="global" >

<aura:attribute name="events" type="delegatemanager__Event__c[]"/>

<lightning:button aura:id="deleteDataButton"
                     label="Delete Data"
                     class="slds-button slds-button__icon--left slds-button--destructive"
                     onclick="{!c.deleteData}" 
                     iconName="utility:delete"
              />

</aura:component>

Controller Snippet

({

    deleteData: function(component, event, helper){
        var action = component.get("c.deleteData");
         action.setCallback(this, function(response){
        var state = response.getState();
        if (state === "SUCCESS") {
                 toastEvent.setParams({
                "title": "Delete!",
                "message": "Data were succesfully deleted.",
                "type": "other",
                "key":"delete"
            });
                toastEvent.fire();
        }
    });
         $A.enqueueAction(action);
    },
})

Apex Class

public with sharing class  LightningComponentController {

@AuraEnabled
    public static void deleteData() {
        try {
            List<Event_Group__c> evG = [SELECT Event_Group_Id__c, Event_Group_Name__c,Event_Description__c,Event_Group_Start_Time__c,Event_Group_End_Time__c FROM Event_Group__c  LIMIT 20];
              if(Schema.sObjectType.Event_Group__c.isDeletable())
            delete evG;
        } catch (Exception e) {
            throw new AuraHandledException('Unable to delete auth: ' + e.getMessage());
        }
    }

}

1 Answer 1

1

Dont use the same method name for component controller and apex method name i.e deleteData. Use unique names for client-side and server-side actions in a component.

If you use same method name component will go into infinite loop. so the page freezes without deleting any records

0

You must log in to answer this question.

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