0

This question has been asked a lot I know and I apologize but I've spent a couple of hours troubleshooting why my record list is empty when the components I've set up are very simple.

I am trying to get records from a custom object and display them as text in the Lightning App.
The custom object is called Order_Item__c.

Component: listOrdItems

<aura:component implements="force:appHostable" controller="fetchOIDetails" >
    <aura:attribute name="oiList" type="Order_Item__c[]"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />  
    <aura:iteration var="item" items="{!v.oiList}" >
    <p>{!item.Name}</p>
    </aura:iteration>
</aura:component>

Controller: listOrdItemsController

({
   doInit : function(component, event, helper) {
        var action = component.get("c.fetchOIList");
        action.setCallback(this, function(data){
            component.set("v.oiList",data.getReturnValue()); 
        });
       console.log('this function ran');
     $A.enqueueAction(action);
    }
})

Server-side Component: fetchOIDetails

public class fetchOIDetails {
    @AuraEnabled
    public static List<Order_Item__c> fetchOIList() {
        List<Order_Item__c> ordLst = new List<Order_Item__c>();
        ordLst = [SELECT Id,Name FROM Order_Item__c];
        return ordLst;
    }
}

Application:

<aura:application extends="force:slds">
    <c:listOrditems/>
</aura:application>
9
  • Try to do a console.log(JSON.parse(JSON.serialize(data.getReturnValue())); (inside the setCallback) to see what comes back form the server Jun 1, 2021 at 13:33
  • @SergioAlcocer, I did that. Page is still blank.
    – Francis M
    Jun 1, 2021 at 13:36
  • check also the data.getState() to see if its 'SUCCESS' and do the console.log of the returned values. Alternatively, enable apex debug logs and see what you get back on apex-side Jun 1, 2021 at 13:38
  • try to check getState() of the response before saving the response in your attribute. action.setCallback(this, function(data){ var state = data.getState(); if (state == 'SUCCESS') { console.log(JSON.parse(JSON.serialize(data.getReturnValue())); component.set("v.oiList",data.getReturnValue()); }else{ console.log('state '+ state); } }); Jun 1, 2021 at 13:41
  • can you please check this query : SELECT Id,Name FROM Order_Item__c in query editor.how many records you will get???.. Jun 1, 2021 at 13:49

1 Answer 1

0

I apologize to everyone, I really do not know what fixed it but it fixed itself. I have no idea what did it. I even created another org just to recreate the problem though I failed and so I decided to run the application again, then suddenly it showed the records and their names.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .