3

I am new to Lightning and i am trying some basic things. I am getting this error in Preview. Pls help.

"Error during init : helper.method is not a function"

Apex Class

public class contactAura {
@AuraEnabled

public static List<Contact> getAllContacts()
{

    return [select id, name from Contact limit 5];    
}
}

component

<aura:component controller="contactAura" >
<aura:attribute name="contactRows" type="Object[]"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<div class="container">
    <p>
        <b> List of Contacts </b>
    </p>
    <table class="table table-bordered table-hover">
        <thead>
            <tr>
                <th><strong> Id </strong></th>
                <th> <strong>  Name </strong> </th>
            </tr>
        </thead>
        <tbody>
            <aura:iteration var="cell" items="{!v.contactRows}">
                <tr>
                    <td> <a href="{! '/'+cell.Id}"> {!cell.Id} </a> </td>
                    <td> {!cell.Name}  </td>
                </tr>
            </aura:iteration>
        </tbody>
    </table>
</div>
</aura:component>

Component Controller

({
doInit : function(component, event, helper) {
    helper.getAllContacts(component);
}
})

Component Helper

({
getAllContacts: function(component, event, helper){
    var action = component.get("c.getAllContacts");
    action.setCallback(this, function(a){
        component.set("v.contactRows", a.getReturnvalue());


    })

    $A.enqueueAction(action);
}
})

Application

<aura:application >
  <link href='/resource/bootstrap/' rel="stylesheet"/>
  <c:AllContactsComp />
</aura:application>
3
  • 2
    remove helper from helper method and then try. Commented Nov 19, 2015 at 10:38
  • 1
    Yes remove helper from Component Helper
    – Ratan Paul
    Commented Nov 19, 2015 at 13:03
  • I've modified your title to make it more descriptive.
    – pchittum
    Commented Nov 20, 2015 at 11:10

2 Answers 2

4

With a quick test of a copy/paste of this code, I found a different error:

Unknown Error : a.getReturnvalue is not a function

So above, you weren't careful with the case-sensitivity of Javascript. So with that corrected, I tried again with the following correction:

a.getReturnValue()
           ^------I made this upper case

After which point, it worked fine.

FYI, I'm not using the bootstrap CSS in mine, but that shouldn't matter.

Why the different error in your instance? Not sure. Could be the compiler in your browser's implementation of JS was failing to compile the whole helper function, instead of catching the call on the inner function. JS works in mysterious ways.

Edit: I was not clear enough, so added the code example.

3
  • Hi Peter I am still getting the error : "Unknown Error : a.getReturnvalue is not a function"
    – Praveen
    Commented Nov 20, 2015 at 12:08
  • Hi Peter. Just one small silly problem. I am unable to return any records to the Lightning Aura Page. only this text is being returned "List of Contacts Id, Name". Pls help
    – Praveen
    Commented Nov 23, 2015 at 4:46
  • I would suggest some use of console.log() in your JS to see if you're actually getting anything back, plus some exception handling. If you still have trouble, I'd recommend a new question.
    – pchittum
    Commented Nov 23, 2015 at 12:57
1

You need to capitalize the 'v' as @Peter said. The line in your helper should look like this:

component.set("v.contactRows", a.getReturnValue());

You must log in to answer this question.

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