You need to sign in to do that
Don't have an account?
Srinivas223
soql queries
Hello All,
I have 3 custom objects namely Parent__c, Child__c, GrandChild__c, I can get the id of the parent from visualforce page. I want to display the grand child records in the visualforce page. I appreciate if anyone could help me with this.
Thank you
I have 3 custom objects namely Parent__c, Child__c, GrandChild__c, I can get the id of the parent from visualforce page. I want to display the grand child records in the visualforce page. I appreciate if anyone could help me with this.
Thank you
Below is the Visual page and class for your requirement using controller extension. In my example i have used the following objects. You just replace with your objects and fields.You shuld have your parent id in url. Please mark as best answers if it works for you..
Account - Parent
Opportunity - Child
OpportunityLineItems - Grand child
VP:
<apex:page standardController="Account" extensions="GrandchildDisplay">
<Apex:pageblock >
<apex:pageBlockTable value="{!oplist}" var="ol">
<apex:column value="{!ol.Id}"/>
<apex:column value="{!ol.name}"/>
<apex:column value="{!ol.Quantity}"/>
<apex:column value="{!ol.product2id}"/>
</apex:pageBlockTable>
</Apex:pageblock>
</apex:page>
Class:
public class GrandchildDisplay {
public list<OpportunityLineItem> oplist {set;get;}
public GrandchildDisplay(apexpages.StandardController std){
list<opportunity> opp = new list<opportunity>();
list<OpportunityLineItem> tempoplist = new list<OpportunityLineItem>();
id accid = apexpages.currentPage().getparameters().get('Id');
opp =[select id,(select id,name,OpportunityId,Product2Id,Quantity from OpportunityLineItems) oplst from Opportunity where accountid=:Accid];
system.debug('accountid ' + accid + ' opporty ' +opp);
for(opportunity op:opp)
{
tempoplist.add(op.OpportunityLineItems);
}
oplist=tempoplist;
}
}
All Answers
Below is the Visual page and class for your requirement using controller extension. In my example i have used the following objects. You just replace with your objects and fields.You shuld have your parent id in url. Please mark as best answers if it works for you..
Account - Parent
Opportunity - Child
OpportunityLineItems - Grand child
VP:
<apex:page standardController="Account" extensions="GrandchildDisplay">
<Apex:pageblock >
<apex:pageBlockTable value="{!oplist}" var="ol">
<apex:column value="{!ol.Id}"/>
<apex:column value="{!ol.name}"/>
<apex:column value="{!ol.Quantity}"/>
<apex:column value="{!ol.product2id}"/>
</apex:pageBlockTable>
</Apex:pageblock>
</apex:page>
Class:
public class GrandchildDisplay {
public list<OpportunityLineItem> oplist {set;get;}
public GrandchildDisplay(apexpages.StandardController std){
list<opportunity> opp = new list<opportunity>();
list<OpportunityLineItem> tempoplist = new list<OpportunityLineItem>();
id accid = apexpages.currentPage().getparameters().get('Id');
opp =[select id,(select id,name,OpportunityId,Product2Id,Quantity from OpportunityLineItems) oplst from Opportunity where accountid=:Accid];
system.debug('accountid ' + accid + ' opporty ' +opp);
for(opportunity op:opp)
{
tempoplist.add(op.OpportunityLineItems);
}
oplist=tempoplist;
}
}
tempoplist.addall(op.OpportunityLineItems);