+ Start a Discussion
Justin LJustin L 

Unknown Error : Unable to find 'doInit'

I'm trying to build a lightning component based on the Trailhead Contacts Nearby project, except using Accounts instead.  I'm getting the following error screen when I try to drag it to a Lightning Page:

User-added image

public with sharing class AcctController {

    public static List<Account> findNearby(Double latitude, Double longitude, Double maxDistance) {
        return Database.query('SELECT Id, Name, BillingStreet, BillingCity, BillingState, Next_Contract_Expiration__c, Current_Contract_Volume__c, Phone FROM Account' +
                       ' WHERE DISTANCE(Location__c, GEOLOCATION(' + latitude + ',' + longitude + '), \'mi\') < '+ maxDistance +
                       ' ORDER BY DISTANCE(Location__c, GEOLOCATION(' + latitude + ',' + longitude + '), \'mi\')');


<aura:component controller="AcctController" implements="flexipage:availableForAllPageTypes">

    <aura:attribute name="maxDistance" type="integer"/>
    <aura:attribute name="latitude" type="Decimal"/>
    <aura:attribute name="longitude" type="Decimal"/>
    <aura:attribute name="Account" type="Account[]"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />

        <h2>Accounts Nearby</h2>
            <aura:iteration items="{!v.Account}" var="Account">
                    <h3><a href="{! '#/sObject/' + Account.Id + '/view'}">{!Account.Name}</a></h3>
                    <aura:if isTrue="{! Account.BillingCity}">
                        <p><a href="{! 'http://maps.apple.com?q=' + Account.BillingStreet + ', ' + Account.BillingCity}">
                            {!Account.BillingCity}, {!Account.BillingState}<br/>
                            {!Account.Current_Contract_Volume__c} + '  ' + {!Account.Next_Contract_Expiration__c}</a></p>
                    <p><a href="{! 'tel:' + Account.phone}">{!Account.Phone}</a></p>


The code is basically the same as the ContactsNearby, which appropriate changes made to desired fields and object, and it does not give off any code errors when saving, so syntax must be somewhat acceptable.  Any thoughts?
Hi Justin,

In the component, you are calling {!doInit} method, have you created any controller class of component where this doInit is defined?
If not, you need to create one like:

Create controller of component and write the code:
    doInit : function(cmp) {
If you don't need this function, just remove the line from your component:
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
Let me know, if you need any other help.

Kevin McAuliffe 14Kevin McAuliffe 14
To reinforce Neetu said above, make sure the function is defined on the component controller.  There can be a controller on the application as well as on the component.  I've gotten these mixed up and ran into the same error that you got.

Thanks ;)
Vivi PioVivi Pio
Thanks for deferentiating controller as component controller and application related controller