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
DeepikareddyDeepikareddy 

In Lighting , getting the values in the Console but not getting values in component

Apex class:
public class Auraopportunity {

    
    @AuraEnabled
    public static list<opportunity> getdata(){
        
      list<opportunity>lstopp =[select id, name, type, amount from opportunity limit 5];   
       return lstopp; 
    }
}

 Component:
<aura:component controller="Auraopportunity">
    <aura:attribute name ="opportunities" type="list"/>
    
    <aura:iteration items="{!v.opportunities}" var="a">
   
   <h1>{!a.id}</h1>
    </aura:iteration>
    
    <aura:handler name="init" value="{!this}" action="{!c.show}"/>
</aura:component>
Controller
({
	show : function(component, event, helper) {
		alert("Hello");
        
        var abc= component.get("c.getdata");
         console.log("Method is invoked");
        abc.setCallback(this,function(response){
             
          var state = response.getState();
             console.log(state);
            
            if(state === "SUCCESS"){
                
                var result = response.getReturnValue();
                console.log(result);
                alert(result);
                component.set("!v.opportunities",  result);
            }else{
                
                 console.log("Failed");
            }
        });
        $A.enqueueAction(abc);
        
	}
})

iam calling in the application :
 
<aura:application >
    <c:Auraoppiteration/>	
</aura:application>
it is not getting display, may i know  , im getting the timeout error itseems, ..
Thanks
Deepika
DeepikareddyDeepikareddy
i have removed  with ,

component.set("v.opportunities",  result); //but not executed.

 
Vijay NirateVijay Nirate
Hi Deepikareddy,

In aura:iteration instead of a.id use a.Id

i.e change <h1>{!a.id}</h1> to <h1>{!a.Id}</h1>

the I in the a.id should be capital i.e : a.Id

this should solve your problem.
Aman PathakAman Pathak
Only thing that need to be changed is in the Lighting component is in place of a.id , make it a.Id.
<aura:component controller="Auraopportunity">
    <aura:attribute name ="opportunities" type="list"/>
    <aura:handler name="init" value="{!this}" action="{!c.show}"/>
    <aura:iteration items="{!v.opportunities}" var="a">
   
   <h1>{!a.Id}</h1>
    </aura:iteration>
    
   
</aura:component>
thanks,
Aman