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

17.6k Views Asked by At

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 :)

2

There are 2 best solutions below

0
On BEST ANSWER

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

0
On

My error was the same but the issue was a missing closing parenthesis after a function like:

action.setCallback(this, function(response){ /* do stuff */ }

But none of my errors were calling out that line. Fix was of course

action.setCallback(this, function(response){ /* do stuff */ });