+ Start a Discussion

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. 


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 >  
            body .bPageBlock .pbBody .red .pbSubheader{
            body .bPageBlock .pbBody .blue .pbSubheader{
            body .bPageBlock .pbBody .green .pbSubheader{
        <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: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}" />
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.
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
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]; }