0

I'm using the Lightning Component Developer guide and stuck at a final step. In the guide, they are using an Expense__c object. In my case I'm trying to use Case. In the final step, they use helper classes to add an expense.

Here is the code they use:

createExpense: function(component, expense) {
this.upsertExpense(component, expense, function(a) {
    var expenses = component.get("v.expenses");
    expenses.push(a.getReturnValue());
    component.set("v.expenses", expenses);
    this.updateTotal(component);
  });
},

upsertExpense : function(component, expense, callback) {
    var action = component.get("c.saveExpense");
    action.setParams({ 
        "expense": expense
    });
    if (callback) {
      action.setCallback(this, callback);
    }
    $A.enqueueAction(action);
}

In the function definition, they use expense and here I want to use case. Except when I do update it, I get an error. Here is my code:

createCase: function(component, case) {
    this.upsertCase(component, case, function(a) {
        var cases = component.get("v.cases");
        cases.push(a.getReturnValue());
        component.set("v.cases", cases);
      });
},

upsertCase : function(component, case, callback) {
    var action = component.get("c.saveCase");
    action.setParams({ 
        "case": case
    });
    if (callback) {
      action.setCallback(this, callback);
    }
    $A.enqueueAction(action);

}

This is the error I get:

Something has gone wrong. Error during init [TypeError: Cannot read property 'apply' of undefined] . Please try again.

  • Did you write Apex controller with saveCase auraEnabled method? – Kiran Machhewar Oct 13 '16 at 22:26
0

You can define the type of the object in 2 places:

In the client side in the component's markup:

<aura:attribute name="case" type="Case" default="{ 'sobjectType': 'Case' , 'OwnerId': 'your id' }"/>

And in your server side AuraEnabled apex controller. Then you return the case you have created to your component's javascript controller.

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.