salesforce
  1. salesforce-apex-datalist-component

apex:dataList Component

The apex:dataList component in Salesforce Visualforce allows you to display a list of records in a customized format. This component is particularly useful when you want to display a list of records in a visually appealing manner.

Syntax

The basic syntax for using the apex:dataList component is as follows:

<apex:dataList value="{!records}" var="record">
  <!-- Child elements here -->
</apex:dataList>

Where:

  • records is a variable containing the list of records to display.
  • record is a variable used to reference each record in the list.

Example

Consider the following example where we will use the apex:dataList component to display a list of accounts:

<apex:dataList value="{!accounts}" var="acc">
  <div class="account-details">
    <p>Name: {!acc.Name}</p>
    <p>Industry: {!acc.Industry}</p>
    <p>Annual Revenue: {!acc.AnnualRevenue}</p>
  </div>
</apex:dataList>

In this example, we are using the apex:dataList component to display a list of accounts. For each account, we are displaying its name, industry, and annual revenue in a visually appealing format.

Output

The output of the above example would be a list of accounts with their details displayed in a customized format.

Explanation

The apex:dataList component works by iterating over the list of records passed to it and rendering the child elements for each record. In the example above, for each account in the list, we are displaying its details in a div element with a class of account-details. The fields of each account are accessed using merge field syntax.

Use

The apex:dataList component is used to display a list of records in a visually appealing format. It is commonly used to display lists of records in data-heavy Visualforce pages.

Important Points

  • The value attribute of the apex:dataList component must reference a variable containing a list of records.
  • The var attribute of the apex:dataList component is used to reference each record in the list.
  • You can apply CSS styles to the child elements to customize the appearance of the list.

Summary

The apex:dataList component in Salesforce Visualforce allows you to create visually appealing lists of records. It works by iterating over a list of records and rendering customized child elements for each record. It is commonly used in data-heavy Visualforce pages to display lists of records in a more visually appealing format.

Published on: