Free computer code on screen

Utilizing Apex Repeat in Visualforce Pages

Utilizing apex:repeat in a Visualforce Page enables iteration through a collection’s contents based on a specified structure. This component supports collections with up to 1,000 items.

When employed within an apex:pageBlockSection or apex:panelGrid component, all content generated by a nested apex:repeat component consolidates into a single cell of the respective apex:pageBlockSection or apex:panelGrid.

It’s important to note that this component cannot function as a direct child of the following components:

The apex:repeat tag possesses the following attributes:

Attribute NameAttribute TypeDescription
firstIntegerThe first element in the collection visibly rendered, where 0 is the index of the first element in the set of data specified by the value attribute. For example, if you did not want to display the first two elements in the set of records specified by the value attribute, set first=”2″.
IdStringAn identifier that allows the repeat component to be referenced by other components in the page.
renderedBooleanA Boolean value that specifies whether the component is rendered on the page. If not specified, this value defaults to true.
rowsIntegerThe maximum number of items in the collection that are rendered. If this value is less than the number of items in the collection, the items at the end of the collection are not repeated.
valueObjectThe collection of data that is iterated over.
varStringThe name of the variable that represents the current item in the iteration.

Example Usage of Apex Repeat

Visualforce page Utilizing Apex Repeat

<apex:page controller="repeatCon" id="thePage">
    <apex:repeat value="{!strings}" var="string" id="theRepeat">
        <apex:outputText value="{!string}" id="theValue"/><br/>
    </apex:repeat>
</apex:page>

Apex Code Implementing Apex Repeat

public class repeatCon {
    public String[] getStrings() {
        return new String[]{'ONE','TWO','THREE'};
    }
}

For further details, please consult the official link provided below:

apex:repeat

Distinguishing Between Apex pageBlockTable And Apex Repeat

With pageBlockTable, all Salesforce styles are automatically inherited, whereas when utilizing apex:repeat, manual addition of table tr td tags and styles becomes necessary. The advantage of apex:repeat lies in the greater control it offers over the display of data.