Visualforce Controllers: Understanding Apex Columns | Salesforce Exam DEV-501

Apex Columns Explained

Question

A single column in a table.

An <apex:column> component must always be a child of an <apex:dataTable> or <apex:pageBlockTable> component.

Note that if you specify an sObject field as the value attribute for an <apex:column>, the associated label for that field is used as the column header by default.

To override this behavior, use the headerValue attribute on the column, or the column's header facet.

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

B.

The correct answer to the question is (B) apex:column.

In Visualforce, a table is typically displayed using the apex:dataTable or apex:pageBlockTable components, which allow you to display data in a tabular format. The apex:column component is used to define a single column within the table.

When using apex:column, you can specify the data that should be displayed in that column using the value attribute. For example, if you want to display the "Name" field from an sObject, you could use the following code:

php
<apex:dataTable value="{!myRecords}" var="record"> <apex:column value="{!record.Name}" /> </apex:dataTable>

By default, the column header will be set to the label of the sObject field that you specified as the value attribute. However, you can override this behavior by using the headerValue attribute or the header facet.

For example, to set a custom header for the column, you could use the following code:

php
<apex:dataTable value="{!myRecords}" var="record"> <apex:column value="{!record.Name}" headerValue="Employee Name" /> </apex:dataTable>

This would display the column with the header "Employee Name" instead of "Name".

In summary, the apex:column component is used to define a single column within a Visualforce table, and allows you to specify the data that should be displayed in that column, as well as customize the column header if needed.