Salesforce Developer Visualforce Iteration Components

salesforce-developer-visualforce

// Salesforce - Developer - Visualforce - Iteratable Components:

We can do the same thing as  <apex:relatedList> in your own Visualforce markup 
using iteration components. An iteration component works with a collection of 
similar items, instead of on a single value. For example, {!Account.contacts} 
is an expression that evaluates to a list of contacts for an account. You can 
use this expression with an iteration component to create a list or table with 
details of these related contacts.

Replace the two <apex:relatedList/> lines with the following markup.

<apex:pageBlock title="Contacts">
   <apex:pageBlockTable value="{!Account.contacts}" var="contact">
      <apex:column value="{!contact.Name}"/>
      <apex:column value="{!contact.Title}"/>
      <apex:column value="{!contact.Phone}"/>
   </apex:pageBlockTable>
</apex:pageBlock>

<apex:pageBlockTable> is an iteration component that generates a table of data, 
complete with platform styling. Here’s what’s going on in your markup.

1. The value attribute of <apex:pageBlockTable> is set to the expression 
   mentioned previously, {!Account.contacts}. This is the list of records that 
   <apex:pageBlockTable> will work with.

2. For each record in that list, one record at a time, <apex:pageBlockTable> 
   assigns that record to the variable named in the <apex:pageBlockTable>’s 
   var attribute. In this case, that variable is named contact.

3. For each record, <apex:pageBlockTable> constructs a new row in the table, 
   using the row defined by the set of <apex:column>components within the body 
   of <apex:pageBlockTable>. The <apex:column> components, in turn, use the 
   contact variable that represents the current record to pull out the field 
   values for that record.

4. Outside of the loop, <apex:pageBlockTable> uses the fields in the 
   <apex:column> components to create column headers, by looking up the label 
   for each field.

The value attribute of <apex:pageBlockTable> is set to the expression mentioned 
previously, {!Account.contacts}. This is the list of records that 
<apex:pageBlockTable> will work with.  For each record in that list, one record 
at a time, <apex:pageBlockTable> assigns that record to the variable named in 
the <apex:pageBlockTable>’s var attribute. In this case, that variable is named 
contact.  For each record, <apex:pageBlockTable> constructs a new row in the 
table, using the row defined by the set of <apex:column>components within the 
body of <apex:pageBlockTable>. The <apex:column> components, in turn, use the 
contact variable that represents the current record to pull out the field values 
for that record.  Outside of the loop, <apex:pageBlockTable> uses the fields in 
the <apex:column> components to create column headers, by looking up the label 
for each field.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License