+ Start a Discussion
Dinesh LodhiDinesh Lodhi 

Lightning issue--Uncaught Error in $A.getCallback() [system is not defined] Callback failed: apex://AccountPracticeLC/ACTION$FetchAccountRecord

Hello Everyone,

I am new to SF Lightning, getting above issue while retrieving 10 accouts record on Lightning Builder App.

Kindly assist to resolve this issue.

----AccountPracticeLC.apxc---------------------

public class AccountPracticeLC {
 public static List<Account> ListAct;
 @AuraEnabled
 public static List<Account> FetchAccountRecord(){
     ListAct = [select Name, AccountNumber, Phone, Industry from Account Limit 10];
     return ListAct;      
    }
}

-------------AccountPracticeLC_Cmp.cmp-----------------

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" controller ="AccountPracticeLC" >
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
      <aura:attribute name="Accounts" type="Account[]"/>
    <section class="slds-card__body">
                   
          <div class="slds-tile slds-hint-parent">
              <p class="slds-tile__title slds-truncate">Name: 
                  <ui:outputText value="{!v.Accounts.Name}"/>
              </p>
        <p class="slds-truncate">Account Number: 
            <ui:outputText value="{!v.Accounts.AccountNumber}"/>
        </p>
        <p class="slds-truncate">Phone:
            <ui:outputNumber value="{!v.Accounts.Phone}" />
        </p>
                      <p class="slds-truncate">Industry:
            <ui:outputText value="{!v.Accounts.Industry}" />
        </p>

    </div>
        </section>  
    
  </aura:component>

--------------------------Controller---------------

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

-------------------------Helper--------------------

({
  FetchAccountRecord: function(component) {
        var action = component.get("c.FetchAccountRecord");
        action.setCallback(this, function(data) {
            var state = data.getState();
            if (component.isValid() && state === "SUCCESS") {
                component.set("v.Accounts", data.getReturnValue());
                system.log(response.getReturnValue());
            }
        });
        $A.enqueueAction(action);
        },    
})
Best Answer chosen by Dinesh Lodhi
Alain CabonAlain Cabon
Hi,

Two errors: reponse instead of data and system.log instead of console.log  (it is javascript not apex)

 system.log(response.getReturnValue());​

 console.log(data.getReturnValue());​

https://developer.mozilla.org/fr/docs/Web/API/Console/log

It lacks also  <aura:iteration items="{!v.Accounts}" var="acc"> ​for the component.
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" controller ="AccountPracticeLC" >
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:attribute name="Accounts" type="Account[]"/>
    <section class="slds-card__body">
      <aura:iteration items="{!v.Accounts}" var="acc"> 
        <div class="slds-tile slds-hint-parent">
            <p class="slds-tile__title slds-truncate">Name: 
                <ui:outputText value="{!acc.Name}"/>
            </p>
            <p class="slds-truncate">Account Number: 
                <ui:outputText value="{!acc.AccountNumber}"/>
            </p>
            <p class="slds-truncate">Phone:
                <ui:outputNumber value="{!acc.Phone}" />
            </p>
            <p class="slds-truncate">Industry:
                <ui:outputText value="{!acc.Industry}" />
            </p>      
        </div>
       </aura:iteration>
    </section>   
</aura:component>

https://trailhead.salesforce.com/fr/projects/quickstart-lightning-components/steps/quickstart-lightning-components

Best regards
Alain

All Answers

Alain CabonAlain Cabon
Hi,

Two errors: reponse instead of data and system.log instead of console.log  (it is javascript not apex)

 system.log(response.getReturnValue());​

 console.log(data.getReturnValue());​

https://developer.mozilla.org/fr/docs/Web/API/Console/log

It lacks also  <aura:iteration items="{!v.Accounts}" var="acc"> ​for the component.
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" controller ="AccountPracticeLC" >
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:attribute name="Accounts" type="Account[]"/>
    <section class="slds-card__body">
      <aura:iteration items="{!v.Accounts}" var="acc"> 
        <div class="slds-tile slds-hint-parent">
            <p class="slds-tile__title slds-truncate">Name: 
                <ui:outputText value="{!acc.Name}"/>
            </p>
            <p class="slds-truncate">Account Number: 
                <ui:outputText value="{!acc.AccountNumber}"/>
            </p>
            <p class="slds-truncate">Phone:
                <ui:outputNumber value="{!acc.Phone}" />
            </p>
            <p class="slds-truncate">Industry:
                <ui:outputText value="{!acc.Industry}" />
            </p>      
        </div>
       </aura:iteration>
    </section>   
</aura:component>

https://trailhead.salesforce.com/fr/projects/quickstart-lightning-components/steps/quickstart-lightning-components

Best regards
Alain
This was selected as the best answer
Dinesh LodhiDinesh Lodhi
Thanks Alain...
It worked..
Saket Ranjan 3Saket Ranjan 3
system.debug is for apex classes, for scripts you should use console.log. 
correct me if i am wrong.