+ Start a Discussion
George WilliamsGeorge Williams 

Quick Start: Lightning Components Broken

For whatever reason the Lightning app built during the above Trailhead project does not work when previewed.  I keep getting this error:

This page has an error. You might just need to refresh it. Error during init [Cannot read property 'apply' of undefined]

No issues with the project chanllenges, in fact I have completed the project trail.  Checked my code, exact same as given during the project steps.
NagendraNagendra (Salesforce Developers) 
Hi George,

May I request you please post the code snippet of what you have done so far so that we can look into it and do the needful accordingly.

George WilliamsGeorge Williams
Apex Controller:
public class MyContactListController {
    public static List<Contact> getContacts(){
        return [select Id,Name,Email,Title,Phone from Contact];


Component Code:

<aura:component controller="MyContactListController">
    <aura:handler name="init" action="{!c.myAction}" value="{!this}"/>
    <aura:attribute name="contacts" type="Contact[]"/>
    	<aura:iteration items="{!v.contacts}" var="contact">
        	<li class="minli"><h3>"{!contact.Name}"</h3></li>

Component Controller Code:
	myAction : function(component, event, helper) {
		var action = component.get("c.getContacts");

App Harnes Code:
<aura:application >
    <c:MyContactList />

Charles ThompsonCharles Thompson
I found a similar issue.  Completed all the steps of Quick Start: Lightning Components in Trailhead, and didn't get any results in the new component.  For anyone who comes after me, the resolution is to edit the Apex controller to look like the following:
File: MyContactListController.apxc
public class MyContactListController {
    public static List<Contact> getContacts(Id recordId) {
        List<Contact> cs = [SELECT Id,
                            FROM   Contact
                            WHERE  AccountId = :recordId
        return cs;
See what I did here?  The original code just returns the SOQL result without storing it in a List variable.  The correct (standard) practice is to declare a local variable, SELECT into the variable, then return the variable.

This should now work for you.
Shalom RubdiShalom Rubdi
Most people seem to be creating an unordered list with the iteration component; however, the challenge markup refers to the lightning:datatable component. 

I used that, was also unable to see any results and got the following error in the console:
The "keyField" is a required attribute of lightning:datatable.
Fixed this by adding the following into the datatable component definition:
.  Now the contacts display as expected like the image below:

Contacts list Lightning component for account page

Documentation reference: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/aura_compref_lightning_datatable.htm
Malini Gali 16Malini Gali 16
You sugestion helped me Shalom. Thanks