You need to sign in to do that
Don't have an account?
Sale 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:
But my Controller shows proper Output while executing via Anonymous window:
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:
But my Controller shows proper Output while executing via Anonymous window:
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
Did you try with above solution, Does it solve your purpose?