+ Start a Discussion
Ajeeth Kumar SAjeeth Kumar S 

i have a two custom object. both object have parent and child relation. i want to display the record in vf page like each and every parent record and below there child record.i need code for develop visualforce page please help me!..

Gulafsha MohammedGulafsha Mohammed
Hello Ajeeth,
Can you specify your requirement? Is your requirement like-:

Parent1
child 11
child 12
Parent2
child 21
child22
child23

Thanks,
Gulafsha
Ajay K DubediAjay K Dubedi
Hi Ajeeth,
Please try this code:

Vf page:
<apex:page controller="parentchildcontroller">
    <apex:pageBlock >
     <apex:repeat value="{!parentList}" var="a">
         
         <apex:outputText value="{!a.name}"> 
        </apex:outputText>  
              
          <apex:repeat value="{!a.Child_obj__r}" var="child">
              <apex:outputText value="{!child.name}">
                       <br/> &nbsp;
              </apex:outputText>
             </apex:repeat>   
         <br/> <br/>
     </apex:repeat>   
        
    </apex:pageBlock>
</apex:page>

Controller Class:

public class parentchildcontroller {
    public List<Parent_Object__c> parentList{get;set;}
    public  List<Child_Object__c> childList;
    public Map<Id,List<Child_Object__c>> mymap{get;set;}
    
  public parentchildcontroller()
  {
      System.debug('>>>>>');
      childList=new List<Child_Object__c>();
      parentList=[SELECT name,(select name from Child_obj__r) from Parent_Object__c ];  
      System.debug('parent list>>'+parentList);
  }
}

You will get the output in this format:

Parent1
 Child record1
 Child record2

Parent2
  Child record3
----

and so no depending on the number of records for your custom objects.

Hope this code will help you.

Thanks.
Ajay Dubedi.