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

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

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

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.