0

I want to enable the button delete function, but not working. :(

see my abbreviated code.

Apex Class:

@AuraEnabled
public static Boolean deleteCliente(Id lstClienteId) {
    Cliente__c n = [SELECT Id FROM Cliente__c WHERE Id = :lstClienteId];

    try{
        delete n;
        return true;
    } catch (Exception e){
        return false;
    }

}

Component:

<aura:attribute name="ListOfCliente" type="Cliente__c[]" />
<aura:handler name="init" value="{!this}" action="{!c.loadClientetList}" />


<form class="account-form" >
                        <input type="hidden" value="{!Cliente.Name}" class="account-name" />
                        <!-- Use a Lightning Base Component To display an icon next to the label -->
                        <lightning:button
                                          label="Delete"
                                          iconName="utility:delete"
                                          iconPosition="left"
                                          variant="destructive"
                                          type="submit"
                                          onclick="{!c.deleteCliente}"

                                          />
                    </form>

Controller:

enter image description here

Helper:

({

deleteSelected : function(component, event, deleteClienteIds) {
    var deleteClienteIds = component.get("v.Cliente.Id");        
    var action = component.get("c.deleteCliente");   

    action.setParams({
        "lstClienteId": deleteClienteIds
    });
    action.setCallback(this, function(response) {
        var state = response.getState();

    console.log("CHEGUEI AQUI");
        if (state === "SUCCESS") {
            if (response.getReturnValue() != '') {
                alert('The following error has occurred. while Delete record-->' + response.getReturnValue());
            } else {
                console.log('check it--> delete successful');
            }   

            // Refresh na Página 
               location.reload();
        }
    });
    $A.enqueueAction(action);
},

})

But, it still does not delete the contact. seemingly all right with the code. I do not understand !!! Thanks for help me

  • <input type="hidden" value="{!Cliente.Name}" class="account-name" /> Where you have defined the attribute called Cliente? – sanket kumar Apr 22 at 4:26
  • hi, thanks for helpe me. I put it but it did not work see now <aura:attribute name="Cliente" type="Cliente__c"/> – Joanes Cavalcanti Apr 22 at 15:22
0
  • deleteSelected has three arguments but you are passing only two, deleteSelected : function(component, event, deleteClienteIds) { ... }. deleteClienteIds is missing.

  • You need to pass Id of the Cliente__c object to this method, then it should work.

  • Not sure where is Cliente is defined, I am assuming you have, so you should pass its id, not name from markup. See below markup:

<input type="hidden" value="{!Cliente.Id}" class="account-name" />

  • hi, thanks for helpe me. So, See my code now component: <aura:attribute name="Cliente" type="Cliente__c"/> {...} <input type="hidden" value="{!Cliente.Id}" class="account-name" /> Controller: helper.deleteSelected(component, event, helper); Helper: deleteSelected : function(component, event) { var currentRecordId = component.get("v.Cliente.Id"); var action = component.get("c.deleteCliente"); action.setParams({ "lstClienteId": currentRecordId }); – Joanes Cavalcanti Apr 22 at 15:49
  • @JoanesCavalcanti can you please update the code in the question itself? It is very hard to read it here in comments. Thanks. – rahul gawale Apr 22 at 16:08
  • ok, Thanks, you will my complete code in bit.ly/2vignOy (bitbucket) – Joanes Cavalcanti Apr 22 at 16:54
  • change line 111 to helper.deleteSelected(component, event, nomeContato); change line 133 to deleteSelected : function(component, event,currentRecordId ){ and delete line 134, – rahul gawale Apr 22 at 17:04
  • @JoanesCavalcanti Please find the working code here, it is implemented for an account object repo link – rahul gawale Apr 23 at 8:03

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.