0
public static List<eioApp__menu__c> getMenuRecords(){
    return [
        SELECT 
            Name,
            eioApp__price__c
        FROM eioApp__Menu__c 
        LIMIT 10
    ];   
}

I have records in this table but the debug shows enter image description here

Here is other components to this app The App

<aura:application extends="force:slds" >
  <c:listOfMenu />

</aura:application>

Here is ListOfMenu Component

<aura:component controller="MenuItemsController" implements="flexipage:availableForAllPageTypes,force:hasRecordId" access="global" >

<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:attribute name="menuList" type="eioApp__Menu__c[]"/>
<lightning:card title="Menu Items"/>
<aura:iteration items="{!v.menuList}" var="item">
    <div>

        <p>{!item.eioApp__price__c}</p>

    </div>

</aura:iteration>

Here is the controller for the component

({
doInit : function(component, event, helper) {
    var action = component.get("c.getMenuRecords");
    action.setCallback(this,function(data){
        var state = data.getState();
        if(state==="SUCCESS"){
            component.set("v.menuRecods",data.getReturnValue());
        }
    })
    $A.enqueueAction(action);


}

})

Here is the apex controller class

public class MenuItemsController {
@AuraEnabled
public List<eioApp__menu__c> getMenuRecords(){
   return [Select name,eioApp__price__c,eioApp__image__c From eioApp__Menu__c Limit 10];



}

}

  • 3
    Is the class running with sharing? What is the org-wide default? Who owns the records? – David Reed Oct 21 at 18:45
  • I did not specify sharing. Wanted it to run as anonymous user – scylla Oct 21 at 18:53
  • 1
    Can you show us how are you trying to use this method? getMenuRecords() What happens if you just run that query in the Query Editor in the developer console? – Carlos Naranjo Oct 21 at 19:51
1

The piece of code you posted is, as such, the definition of a method.

Just running this code will make sure that the method getMenuRecords() is defined, but it will not necessarily run it. So the query inside it will not necessarily run.

In order to have the query run, you need to either actually call the method that you defined, or don't define it as a method.

Call the method:

public static List<eioApp__menu__c> getMenuRecords(){
    return [
        SELECT 
            Name,
            eioApp__price__c
        FROM eioApp__Menu__c 
        LIMIT 10
    ];   
}

getMenuRecords();

Or don't define as method:

List<eioApp__Menu__c> menuList = [
        SELECT 
            Name,
            eioApp__price__c
        FROM eioApp__Menu__c 
        LIMIT 10
    ];   
system.debug(menuList);

And well.. since the only thing that happens in the method is running a soql query, you might just as well paste the query into Query Editor and run it there..

  • You are absolutely right about defining the method. Running the code without defining it as a method actually returned the required records. I will work on this debug to figure out which area of my code needs review. Thank you for the insight. – scylla Oct 22 at 16:35
  • I have added the content of the app to the question – scylla Oct 22 at 16:50
  • ok, if you have any additional questions, I'd suggest posting a new question, in order to prevent things from getting messy.. – Guy Clairbois Oct 23 at 14:39
  • I think I am having namespace issues from my search so far. I have created a post if you can help me out. salesforce.stackexchange.com/questions/282451/… – scylla Oct 23 at 16:25
0

Of you are sure that your query is well formed, the next step is check the permissions for the profile that your user is using

  • The query runs in query editor as required. Like @Guy said, I have to review where I am actually calling the method. – scylla Oct 22 at 16:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.