+ Start a Discussion
Sunil NandipatiSunil Nandipati 

Error during init [Assertion Failed!: Unknown controller action 'getExpenses' : undefined]

I am trying the Lightning ExpenseTracker app.

During Step 3 - Load the Expense Data, i am running into this error.

"This page has an error. You might just need to refresh it. Error during init [Assertion Failed!: Unknown controller action 'getExpenses' : undefined]"

Has anybody experienced the same?
Sunil NandipatiSunil Nandipati
Here is the documentation i am referring to. https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/qs_aotp_app_step3_model.htm
brahmaji tammanabrahmaji tammana
Hi,

Please share the code.

Thanks
Sunil NandipatiSunil Nandipati
@Piyush_soni @Brahmajit

Here u go

ExpenseTracker.app

<aura:application extends="force:slds">  
    <div class="slds">
        <div class="slds-page-header">
          <div class="slds-grid">
            <div class="slds-col slds-has-flexi-truncate">
              <p class="slds-text-heading--label">Expenses</p>
              <div class="slds-grid">
                <div class="slds-grid slds-type-focus slds-no-space">
                  <h1 class="slds-text-heading--medium slds-truncate" title="My Expenses">My Expenses</h1>
                </div>
              </div>
            </div>
          </div>
        </div>
        
        <div class="slds-col--padded slds-p-top--large">
            <c:Form />
        </div>
    </div>
    </aura:application>

Form.cmp

<aura:component controller="ExpenseController" implements="force:appHostable">
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <aura:attribute name="expenses" type="Expense__c[]"/>
  <aura:attribute name="newExpense" type="Expense__c"
         default="{ 'sobjectType': 'Expense__c',
                         'Name': '',
                         'Amount__c': 0,
                         'Client__c': '', 
                         'Date__c': '',
                         'Reimbursed__c': false
                       }"/>
  <!-- If you registered a namespace, replace the previous aura:attribute tags with the following -->
  <!-- <aura:attribute name="expenses" type="myNamespace.Expense__c[]"/> 
  <aura:attribute name="newExpense" type="myNamespace__Expense__c"
               default="{ 'sobjectType': 'myNamespace__Expense__c',
                          'Name': '',
                          'myNamespace__Amount__c': 0,
                          'myNamespace__Client__c': '',
                          'myNamespace__Date__c': '',
                          'myNamespace__Reimbursed__c': false
                         }"/> -->
  <!-- Attributes for Expense Counters -->
  <aura:attribute name="total" type="Double" default="0.00" />
  <aura:attribute name="exp" type="Double" default="0" />

  <!-- Input Form using components -->
  <div class="container">
    <form class="slds-form--stacked">
      <div class="slds-form-element slds-is-required">
        <div class="slds-form-element__control">

       <!-- If you registered a namespace,
            the attributes include your namespace.
            For example, value="{!v.newExpense.myNamespace__Amount__c}" -->

          <ui:inputText aura:id="expname" label="Expense Name"
                        class="slds-input"
                        labelClass="slds-form-element__label"
                        value="{!v.newExpense.Name}"
                        required="true"/>
         </div>
       </div>
       <div class="slds-form-element slds-is-required">
         <div class="slds-form-element__control">
           <ui:inputNumber aura:id="amount" label="Amount"
                           class="slds-input"
                           labelClass="slds-form-element__label"
                           value="{!v.newExpense.Amount__c}"
                           placeholder="20.80" required="true"/>
          </div>
        </div>
        <div class="slds-form-element">
          <div class="slds-form-element__control">
            <ui:inputText aura:id="client" label="Client"
                          class="slds-input"
                          labelClass="slds-form-element__label"
                          value="{!v.newExpense.Client__c}"
                          placeholder="ABC Co."/>
           </div>
         </div>
         <div class="slds-form-element">
           <div class="slds-form-element__control">
             <ui:inputDateTime aura:id="expdate" label="Expense Date"
                               class="slds-input"
                               labelClass="slds-form-element__label"
                               value="{!v.newExpense.Date__c}"
                               displayDatePicker="true"/>
            </div>
          </div>
          <div class="slds-form-element">
            <ui:inputCheckbox aura:id="reimbursed" label="Reimbursed?"
                              class="slds-checkbox"
                              labelClass="slds-form-element__label"
                              value="{!v.newExpense.Reimbursed__c}"/>
            <ui:button label="Submit" 
                       class="slds-button slds-button--neutral"
                       labelClass="label"
                       press="{!c.createExpense}"/>
           </div>
    </form>
  </div><!-- ./container-->

  <!-- Expense Counters -->
  <div class="container slds-p-top--medium">
        <div class="row">
            <div class="slds-tile ">
                <!-- Make the counter red if total amount is more than 100 -->
                <div class="{!v.total >= 100 
                     ? 'slds-notify slds-notify--toast slds-theme--error slds-theme--alert-texture' 
                     : 'slds-notify slds-notify--toast slds-theme--alert-texture'}">
                    <p class="slds-tile__title slds-truncate">Total Expenses</p>
                    $<ui:outputNumber class="slds-truncate" value="{!v.total}" format=".00"/>
                </div>
            </div>
            <div class="slds-tile ">
                <div class="slds-notify slds-notify--toast slds-theme--alert-texture">
                      <p class="slds-tile__title slds-truncate">No. of Expenses</p>
                      <ui:outputNumber class="slds-truncate" value="{!v.exp}"/>
                  </div>
            </div>
        </div>
    </div>
          <!-- Display expense records -->
          <div class="container slds-p-top--medium">
              <div id="list" class="row">
                <!-- aura:iteration items="{!v.expenses}" var="expense">
                    <If you’re using a namespace, use myNamespace:expenseList instead>
                       <c:expenseList expense="{!expense}"/>
                </aura:iteration-->
                  
                 <aura:iteration items="{!v.expenses}" var="expense">

                     <!-- If you’re using a namespace, 
                          use the format 
                          {!expense.myNamespace__myField__c} instead. -->

                     <p>{!expense.Name}, {!expense.Client__c}, 
                        {!expense.Amount__c}, {!expense.Date__c}, 
                        {!expense.Reimbursed__c}</p>                     
                </aura:iteration>
              </div>
          </div> 
</aura:component>

FormController.js

({
    doInit : function(component, event, helper) {
       //Update expense counters
       helper.getExpenses(component);
    },//Delimiter for future code
})

FormHelper.js

({
  getExpenses: function(component) {
        var action = component.get("c.getExpenses");
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (component.isValid() && state === "SUCCESS") {
                component.set("v.expenses", response.getReturnValue());
                this.updateTotal(component);
            }
        });
        $A.enqueueAction(action);
  },
  updateTotal : function(component) {  
      var expenses = component.get("v.expenses");
      var total = 0;
      for(var i=0; i<expenses.length; i++){
          var e = expenses[i];

          //If you’re using a namespace, use e.myNamespace__Amount__c instead
          total += e.Amount__c;
      }
      //Update counters
      component.set("v.total", total);
      component.set("v.exp", expenses.length);
  },//Delimiter for future code

})

Apex Controller

public with sharing class ExpenseController {
    @AuraEnabled
    public static List<Expense__c> getExpenses() {

        // Perform isAccessible() check here
        return [SELECT Id, Name, Amount__c, Client__c, Date__c,
        Reimbursed__c, CreatedDate FROM Expense__c];
    }
}
brahmaji tammanabrahmaji tammana
Hi,

This could be due to 3 equivalent to opeartors in if condition. Try to remove one and test.

            if (component.isValid() && state === "SUCCESS") {

Thanks
Brahma
sfdcMonkey.comsfdcMonkey.com
hi Sunil Nandipati 
it's happen becuse of your helper function name is "getExpenses" and your apex class method name also "getExpenses" so its get  confuse between them 
so change you helper method name 
i hope it helps you.
Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper soltuions for others
thanks 

http://sfdcmonkey.com  (http://sfdcmonkey.com )
 
Ruwantha  LankathilakaRuwantha Lankathilaka
First check the button call. I had the same issue. My mistake was press="myenent" should be corrected to press="{!c.myevent"}