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
Sale IT UPSale IT UP 

Not able to show the Related Child record on Visualforce Page

APEX code:

public with sharing class InnerSOQLQuery {
    
    
    public List<Invoice__c> invList {get;set;}
    
   public List<Item_Detail__c> itemDetail {get;set;}
    
    public  void getRelatedRecords(){
   
     itemDetail = new List<Item_Detail__c>();
            
 invList = [SELECT Invoice_Number_c, Product_Detailsc, (SELECT Name, Quantityc, Ratec FROM Item_Detailsr LIMIT 7) FROM Invoice_c WHERE Id = 'a015w00001FG4gz'];
      
        for(Invoice__c Invs:invList){
            
            for( Item_Detail_c itm:Invs.Item_Details_r){
                itemDetail.add(itm);
                system.debug('Item Name-->'+ itm.Name+ '-->Rate-->'+itm.Rate_c + '-->Quantity-->'+itm.Quantity_c);
            }
        }  
        system.debug('Item Name-->'+ itemDetail);
       
    }
}

VF Code>

<apex:page controller="InnerSOQLQuery"   docType="html-5.0" standardStylesheets="false" applyBodyTag="false" applyHtmlTag="true">

  <apex:pageBlock title="My Content">
    <apex:repeat value="{!invList}" var="acct">
        <apex:outputText value="{!acct.Product_Details__c}"/>
        
        <apex:repeat value="{!acct.Item_Details__r}" var="obj2">
            <apex:outputText value="{!obj2.Name}"/>
        </apex:repeat>
    </apex:repeat>
</apex:pageBlock>
</apex:page>

Result:

User-added image

But my Controller shows proper Output while executing via Anonymous window:

It fetches Child records
Dushyant SonwarDushyant Sonwar
Hi ,

Seems like this org has sharing rule, which is private for Invoice_c Object.

Go to this record a015w00001FG4gz and change owner to yourself.

or 

Remove with sharing keyword in class.

public  class InnerSOQLQuery
Dushyant SonwarDushyant Sonwar
You can also add without sharing keyword.
Dushyant SonwarDushyant Sonwar


Did you try with above solution, Does it solve your purpose?