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

Stefanvdk picture Stefanvdk · Nov 2, 2016 · Viewed 16k times · Source

I'm stuck with a Lightning component that doesn't render. I get a strange error immediately: This page has an error. You might just need to refresh it. Error during init [Cannot read property 'apply' of undefined].

I'm stuck now for a long time and can't figure out what is wrong with the code. Here you can see my code:

Component:

<aura:attribute name="recordId" type="String" default='500b000000cOxah' />
<aura:attribute name="case" type="Case" />
<aura:attribute name="tasks" type="Task[]"/>

<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

<c:CaseActivityTrackerHeader />

<aura:iteration items="{!v.tasks}" var="task">
    <c:CaseActivityTrackerTimeline task="{!task}"/>
</aura:iteration>

<aura:iteration items="{!v.tasks}" var="task">
    <h3>{!v.task.Subject}</h3>
</aura:iteration>

<h3>{!v.case.Subject}</h3>
<h3>{!v.recordId}</h3>

({
doInit: function(component, event, helper) {
    //helper.getCase(component, event);
    //helper.getTasks(component, event);
    // Set the attribute value. 
    // You could also fire an event here instead.
    component.set("v.recordId", "controller init magic!");
}

})

App

<aura:application extends="force:slds">

<c:CaseActivityTracker />

<!-- 
<c:camping />
-->

I really somebody can help me! Thanks in advance :)

Answer

Stefanvdk picture Stefanvdk · Nov 3, 2016

Found it! It was in the helperclass (which I now realise I didn't post here) and it was a variable 'case' that SFDC interpreted as a sobject case instead of var case. By changing the var name to 'Case' the issue was fixed