You need to sign in to do that
Don't have an account?
Sale IT UP
Not able to display 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:
<apex:page controller="InnerSOQLQuery" docType="html-5.0" standardStylesheets="false" applyBodyTag="false" applyHtmlTag="true" action="{!getRelatedRecords}">
All Answers
<apex:page controller="InnerSOQLQuery" docType="html-5.0" standardStylesheets="false" applyBodyTag="false" applyHtmlTag="true" action="{!getRelatedRecords}">
Yes! your solution worked for me :)
@David Zhu
Adding further query to esixting thread:
In below SOQL query, I do not wish to provide hardcode Record ID instead want to fetch Record ID from VF page.
invList = [SELECT Invoice_Number_c, Product_Detailsc, (SELECT Name, Quantityc, Ratec FROM Item_Detailsr LIMIT 7) FROM Invoice_c WHERE Id = 'a015w00001FG4gz'];
In that case how should I proceed?
I tried below code, but it failed on VF page:
APEX-->
public with sharing class InnerSOQLQuery {
public Id InvId;
public List<Invoice__c> invList {get;set;}
public List<Item_Detail__c> itemDetail {get;set;}
public void getRelatedRecords(String InvId){
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 =: InvId];
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);
}
}
Error on VF Page:
Please help me!
public void getRelatedRecords(String InvId){
=》 public void getRelatedRecords(){
You already have variable invid defined in your class.
You can either set in in class instantiation method or in getrelatedrecords method