+ Start a Discussion
Ravi K 47Ravi K 47 

Display parent ,list of child and list of grand child records in visualforce page

Hello All,

I have a requirement to display for each Parent ,list of child records and their list of grand parent records in a visualforce page.
Parent and child have lookup relationship .
But Child to Grand Child are not having any relationship but in GrandChild Object i have one text field "Parent Id " in that filed The Child record id is storing.

User-added image

Apex Class :
public  without sharing class Parentchildgrandchild {
    public string str;
    public list<Contact> Pilist;
    public Map<Contact,list<Grandchild__c>> PIMcamap {get;set;}
    Map<Account,List<Contact>> IPPIMap {get;set;}
    public Parentchildgrandchild(ApexPages.StandardController controller) {
        String pcId = ApexPages.currentPage().getParameters().get('id');
        PIMcamap= new Map<Contact,list<Grandchild__c>>();
         IPPIMap = new Map<Account,List<Contact>>();
        test__c pc= [select id from test__c where id =:pcId];
		for(Account Ip:[select id,name,from Account where test__c =:pcId])
				for(Contact pi :[SELECT id,name,parent from Contact where Account =:ip.id order by LastModifiedDate ])
					PIList=new List<Contact>();
					list<Grandchild__c> ca= new list<Grandchild__c>();
					ca=[select id, name, parentid from Grandchild__c where parentid=:str];
    public class PIwrapper {
        public Account IP {get;set;}
        public Contact pi{get;set;}
        public Grandchild__c mca {get;set;}

VisuaForce Page :
<apex:page renderAs="pdf" standardController="MedConnect__Product_Complaint__c" extensions="Parentchildgrandchild">
                  <apex:repeat value="{!IPPIMap}" var="ac">
                      <table width = "100%" row ="1" column="3" >
					  <tr><th width = "500">Name #</th></tr>
					  <tr><td >{!ac.Name}</td></tr>
					  <tr><th>Child Name</th></tr>
					   <apex:repeat value="{!IPPIMap[ac]}" var="child"> 
							<tr><th>Grand Child Name</th></tr>
									<apex:repeat > 

Due to not having any relationship between Child and GrandChild ,i have created a Wrapper class for that and store thevalues.

From the Apex Class im able to store values of 
Parent and List of Child Records into the map ==> IPPIMap and 
Child record and list of  GrandChild Records ==>PIMcamap

But while referencing in the visualforce page im getting the  below error 

Unknown property 'ParentchildgrandchildStandardController.IPPIMap'

Could you please check and help me on this request .
Hey Ravi,

Try this
Make this as Public  Map<Account,List<Contact>> IPPIMap {get;set;} at line number 7...

Thank You,

Ravi K 47Ravi K 47
Oh..My Bad ..I missed Public . Thanks Rajesh,

Hello All,

Now i want to display information in PDF format as below for each parent.

Could you please help me on this request.

You can display Grand Child records in a table with all childs or separeted with comas (,)

User-added image

Ravi Kumar k
Hello Ravi,
First you have the page as "RenderAs" = PDF and design the page in the required format.
Let me know if you need more help

Thank You,