Skip to main content
2 respuestas
  1. 13 oct 2018, 07:03
    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.
0/9000