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
sbeniwalsbeniwal 

PageBlockTable data iteration

I am just trying to understand the data iteration. Here is a snippet from visualforce documentation:

 

<apex:page standardController="Account">
   <apex:pageBlock title="Contacts">
      <apex:pageBlockTable value="{!account.Contacts}" var="contact">
         <apex:column value="{!contact.Name}"/>
      </apex:pageBlockTable>
   </apex:pageBlock>
</apex:page>

 

What I want to know is: how does this related in the context of custom objects? Let's say I have a parent object TestCase and another child object TestCaseReview. I am trying to do the below, but it is failing:-

 

<apex:page standardController="TestCase__c">        
        <apex:pageblock TITLE="Test">                           
              <apex:pageBlockTable value="{!TestCase__c.TestCaseReview__c}" var="tst">
                 <apex:column value="{!tst.Remarks__c}"/>
              </apex:pageBlockTable>
        </apex:pageblock>        
</apex:page>

 

Please help. Thanks.

Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan

Hi,

 

Pageblock table iterations are done based on the list of values. So, to explain what happens am using the following controller to get the list of record. It shows you that, you are getting the child records that matched with the parent id.

 

So, your code is same like what is given below.

 

VF page

<apex:page standardController="TestCase__c" extensions="listcontrol">        
        <apex:pageblock TITLE="Test">                           
              <apex:pageBlockTable value="{!Listvalues}" var="tst">
                 <apex:column value="{!tst.Remarks__c}"/>
              </apex:pageBlockTable>
        </apex:pageblock>        
</apex:page>

 

Controller:

public class listcontrol{

   public TestCase__c tes{get;set;}

   public List<TestCaseReview__c> Listvalues{get;set;}

 

   public listcontrol(Apexpages.StandardController con){

        con = (TestCase__c)ocn.getRecord();

        Listvalues = [select Remarks__c, parentID__c from TestclassReview__c where parentID__c =: con.id];

   }

}

 

Hope so this helps you...!

Please mark this answer a Solution and please give kudos by clicking on the star icon, if you found this answer as helpful.

 

ledwardsledwards

Well have you retrieved the child objects that belong with that parent object? I had to do something similar but I had to query for the child objects to use first. Then you can just access the child list in the parent objects table. 

 

So you would want to do something like this:

 

List<TestCase__c> temp = [SELECT Id, (Select Id, Remarks__c From TestCaseReview__c) FROM TestCase__c];
<apex:page standardController="TestCase__c">        
        <apex:pageblock TITLE="Test">                           
              <apex:pageBlockTable value="{!temp.TestCaseReview__c}" var="tst">
                 <apex:column value="{!tst.Remarks__c}"/>
              </apex:pageBlockTable>
        </apex:pageblock>        
</apex:page>