1

I'm trying initialize an array of custom object and I get the following error:

Error during init [TypeError: Cannot read property 'apply' of undefined]

Object Name: Expense__c

Namespace: imaginicom

I have declared the attribute like this in Form Component.

<aura:attribute name="expenses" type="imaginicom.Expense__c[]"/>  

<!-- Display expense records -->
      <div class="container slds-p-top--medium">
          <div id="list" class="row">
             <aura:iteration items="{!v.expenses}" var="expense">

                <p>{!expense.imaginicom__Name}, 
                     {!expense.imaginicom__Client__c},
                    {!expense.imaginicom__Amount__c}, 
                     {!expense.imaginicom__Date__c},
                    {!expense.imaginicom__Reimbursed__c}</p>

            </aura:iteration>
          </div>
      </div> 

Form Controller

({
    doInit : function(component, event, helper) {

        helper.getExpenses(component);
    }
})

Form Helper

({
    getExpenses : function(component) {
        console.log("getExpenses");

       var action = component.get("c.getExpense");

       action.setCallback(this, function(response) {

           if (component.isValid()) {
               console.log(JSON.stringify(response.getReturnValue()));                            

               //This is where I get error
               component.set("v.expenses", response.getReturnValue() ); 
            }

       });

       $A.enqueueAction(action);  
    }

})

Apex Class

public with sharing class ExpenseController {

    @AuraEnabled
    public static List<Expense__c> getExpense(){

        // Perform isAccessible() check here
        return [SELECT Id, Name, Amount__c, Client__c, Date__c,
        Reimbursed__c, CreatedDate FROM Expense__c];

    }

} 

Kindly help me out.

1 Answer 1

2

You need to tweak your attribute definition.

Change it to:

<aura:attribute name="expenses" type="imaginicom__Expense__c[]"/>

You had defined it as namespace.ObjectName when it should be namespace__ObjectName

For more examples, usages, go here

1
  • I tried it like imaginicom__Expense__c[] , but that too didn't work. Sep 23, 2016 at 8:57

You must log in to answer this question.

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