function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vignesh RamshettyVignesh Ramshetty 

How to shoe records on Aura getting error with below code

Apex Class:
Public with sharing class AccountHealper{

@AuraEnabled (cacheable=true) 

  public static List<Account> getfunction() {
  list<Account> varacclist = new list<Account> ();
  
  varacclist = [SELECT id,  Name FROM Account];
  
  Return varacclist;
  }
  }



<aura:component controller = "AccountHealper">


<aura:attribute name = "contactlist" type = "object"/>



<lightning:button label = "click here" onclick = "{!c.handeler}"/>


    <aura:iteration items = "{!v.contactlist}" var = "varcon"/>
    
   <p>  {!varcon}</p>


</aura:component>



({

   handeler : function(event,component,helper){


       var action = component.get("c.getfunction");

       action.setCallback(this,function(responce){

           var state = response.getState();

      if(state == "SUCCESS"){

           var result = response.getReturnValue();


         component.set("v.contactlist",result);

  }





});
    $A.enqueueAction(action);
}
})

User-added image
This page has an error. You might just need to refresh it. Action failed: c:ittortercomponent$controller$handeler [component.get is not a function] Failing descriptor: {c:ittortercomponent$controller$handeler}
Best Answer chosen by Vignesh Ramshetty
Sai PraveenSai Praveen (Salesforce Developers) 
Hi.

Can you try the below Aura Component. First no need of onclick button you can use init method for it. If you still need onlick you can use the same.

Aura:
 
<aura:component controller = "AccountHealper">


<aura:attribute name = "contactlist" type = "List"/>



<aura:handler name="init" value="{!this}" action="{!c.doInit}" />


    <aura:iteration items = "{!v.contactlist}" var = "varcon">
    
<tr>
                   
                    <th scope="row">{!varcon.Id}</th>
                    <td>{!varcon.Name}</td>                                        
                </tr>
    </aura:iteration>


</aura:component>

Aura Contraoller:
 
({
    doInit : function(component, event, helper) {
        helper.getAccounts(component);
    }
})

Aura Helper:
 
({
    getAccounts : function(component) {
        var action = component.get("c.getfunction");
        
        //Set up the callback
        var self = this;
        action.setCallback(this, function(actionResult) {
            var state = actionResult.getState();
            if (component.isValid() && state === "SUCCESS") {
                component.set("v.contactlist", actionResult.getReturnValue());
            }            
        });
        $A.enqueueAction(action);
    }
})

Apex Class:
 
Public with sharing class AccountHealper{

@AuraEnabled (cacheable=true) 

  public static List<Account> getfunction() {
  list<Account> varacclist = new list<Account> ();
  
  varacclist = [SELECT id,  Name FROM Account];
  
  Return varacclist;
  }
  }

​​​​​​​​​​​​​​Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi.

Can you try the below Aura Component. First no need of onclick button you can use init method for it. If you still need onlick you can use the same.

Aura:
 
<aura:component controller = "AccountHealper">


<aura:attribute name = "contactlist" type = "List"/>



<aura:handler name="init" value="{!this}" action="{!c.doInit}" />


    <aura:iteration items = "{!v.contactlist}" var = "varcon">
    
<tr>
                   
                    <th scope="row">{!varcon.Id}</th>
                    <td>{!varcon.Name}</td>                                        
                </tr>
    </aura:iteration>


</aura:component>

Aura Contraoller:
 
({
    doInit : function(component, event, helper) {
        helper.getAccounts(component);
    }
})

Aura Helper:
 
({
    getAccounts : function(component) {
        var action = component.get("c.getfunction");
        
        //Set up the callback
        var self = this;
        action.setCallback(this, function(actionResult) {
            var state = actionResult.getState();
            if (component.isValid() && state === "SUCCESS") {
                component.set("v.contactlist", actionResult.getReturnValue());
            }            
        });
        $A.enqueueAction(action);
    }
})

Apex Class:
 
Public with sharing class AccountHealper{

@AuraEnabled (cacheable=true) 

  public static List<Account> getfunction() {
  list<Account> varacclist = new list<Account> ();
  
  varacclist = [SELECT id,  Name FROM Account];
  
  Return varacclist;
  }
  }

​​​​​​​​​​​​​​Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
This was selected as the best answer
Vignesh RamshettyVignesh Ramshetty
If I want to show  by button click then how to do it