3

So I have managed to get the object I want to delete through my method, however I am not sure how I would go about deleting it - I have spent the last thirty minutes going through the documentation and looking on here but just can't seem how to do it. So far I have this in my controller:

destroy : function(component, evt, helper) {
  var expense = component.get("v.expense");
}

I was wondering how I would destroy this instance.

PS

I understand that I need more experience but I like to jump into things and find things out for myself plus it makes me research and read about a variety of things finding out the issue.

  • do you want to delete expense or the component itself. If the expense then [pass them in controller and perform DML. – Tushar Sharma Jan 26 '16 at 11:55
  • ah thank you I've seen my problem now I was trying to delete the expense – user26719 Jan 26 '16 at 11:57
  • Would you have any tips on how to do that by any chance? :) – user26719 Jan 26 '16 at 11:58
1

first pass this list in controller

destroy : function(component) {
    var action = component.get("c.dltexpense");

    action.setParams({
        expenseList  : component.get("v.expense");
    });

    action.setCallback(this, function(a) {
        if (a.getState() === "SUCCESS") {
            console.log(a.getReturnValue());
        } else if (a.getState() === "ERROR") {
            $A.log("Errors", a.getError());
        }
    });

    $A.enqueueAction(action);
}

Now in controller delete this records

 @AuraEnabled
    public static boolean dltexpense(List<expense__c> expenseList ) {
       delete expenseList;
       return true;
    }

use this. It will solve your problem.

  • I've tried this and keep running into this issue: Cannot read property 'setParams' of undefined – user26719 Jan 26 '16 at 12:26
  • which line causing this error – Tushar Sharma Jan 26 '16 at 12:28
  • I believe it is this code here action.setParams({ expenseList : component.get("v.expense") }); – user26719 Jan 26 '16 at 12:29
  • did you add controller in component. Also check if you are getting record in component.get("v.expense") – Tushar Sharma Jan 26 '16 at 12:36
  • Yeah I have a component already and I am getting the record as its being used in the same controller in a different method – user26719 Jan 26 '16 at 12:44

Your Answer

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