Salesforce - Records, Fields and Tables


Advertisements

We have already seen how to get the values of a record using the standard controller. But we can also display the field values in a more formatted way by using additional controllers.

In this chapter, we will see how to display the fields of an object and the data of a details table in a Master-detail relation.

Display Fields

When we want to display the fields of a record in a formatted manner with column headers, rather than just the labels and values, we can use the OutputField option. The code given below shows the apex program to display the filled data from Contact. As you can see, we do not need the labels to be in place to indicate the field values.

vf s record fields tables code

To preview the result of the above code, we use the ID of the record as described in the previous chapter. The result shows the following output showing the field values of the records along with column headers.

vf s record fields tables1

Display Tables

We can display all the records of a details table by taking a value from a master table. For example, we can display all the contacts associated with an account. In such case, we use the iteration component which in our case is the contacts table linked to account. Below is the code to display all the contacts associated with the Account table.

vf s record table code

On previewing the output form the above code, we get the following result.

vf s record table result
Advertisements