function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Bob.390672021994282E12Bob.390672021994282E12 

Parent Child records

I have two objects that I am trying to display on a screen. The parent works fine however the child records are not displaying anything. 
When I place an input value on the screen the input value doesnt even display. Am I missing something?
Yes there are records associated to the parent record already. 

Controller

public with sharing class ParentChild {

 private ApexPages.StandardController NormalSalesforceController {get; set;}
 public parent__c CurrentParentRecordId{get; set;}
 public List<child__c> childrecords {get; set;} // declare the list of child records. 
  
 public ParentChild(ApexPages.StandardController NormalSalesforceController){    

CurrentParentRecordId = [Select Id, Next_Step__c from Parent__c where id = :apexPages.currentPage().getParameters().get('id')];
}
 public List<child__c> getUserValue() {    
      List<child__c> UserValue= [SELECT Id, name, Field__c, Field_2__c, User__c, Parent__c FROM child__c WHERE Parent__c =:CurrentParentRecordId.id];
  return Uservalue;        
 }
}




<apex:page standardController="Parent__c" extensions="ParentChild" tabstyle="Account">
<apex:form >  
     <style>
            body .bPageBlock .pbBody .red .pbSubheader{
                background-color:#c00000;
            }
            body .bPageBlock .pbBody .blue .pbSubheader{
                background-color:#0000FF;     
            }
            body .bPageBlock .pbBody .green .pbSubheader{
                background-color:#7FFF00;
        }
      </style>       
        <apex:pageBlock title="Parent">  
        <apex:outputPanel styleClass="red" layout="block">
            <apex:pageBlockSection title="The parent Information" columns="3">            
            <apex:inputField value="{!Parent__c.Name}"/> 
            <apex:inputField value="{!Parent__c.Version_Number__c}"/> 
            <apex:inputField value="{!Parent__c.User__c}"/> 
       </apex:pageBlockSection>
        </apex:outputPanel> 
       </apex:pageblock>

        <apex:pageBlock title="Child">
        <apex:outputPanel styleClass="blue" layout="block">
        <apex:pageBlockSection title="The child Information" columns="3">     
        <apex:pageBlockTable value="{!Uservalue}" var="Child">
            <apex:inputField value="{!Child.Name}" />
              </apex:pageBlockTable>
          </apex:pageBlockSection>
          
         </apex:outputPanel>
    </apex:pageBlock>
        
    
</apex:form>
</apex:page>
Balaji BondarBalaji Bondar
Hi Bob,
You can query child fields through a subquery like so:
select Id, Name, (select Id, Name from Child__r) from Parent
Store the results in a list of the parent objects:
list<Parent__c> liParents = [select Id, Name, (select Id, Name from Child__r) from Parent];
Then you can then loop over the children in the page with something like this:
 
<apex:repeat var="p" value="{!liParents}"> <apex:outputText value="{!p.Name}: "/> <ul> <apex:repeat var="c" value="{!p.Child__r}"> <li><apex:outputText value="{!c.Name}"/></li> </apex:repeat> </ul> </apex:repeat>

Important :
If this is what you were looking for then please mark it as a "SOLUTION" or You can Click on the "Like" Button if this was beneficial for you.
Bob.390672021994282E12Bob.390672021994282E12
That would work to display the records but you would be able to save the child record data Bryan Revelant Sent from my smart phone
Bob.390672021994282E12Bob.390672021994282E12
O, this is how it should be... Put the query in the constructor class and call it from the visualforce page. public ParentChild(ApexPages.StandardController NormalSalesforceController){ parent = [select id, name, version_number__c, user__c from parent__c where id = :ApexPages.currentPage().getParameters().get('id')]; UserValue= [SELECT Id, name, Field__c, Field_2__c, User__c, Parent__c FROM child__c WHERE Parent__c =:parent.id]; }