Standard Controller


Add the Id of any Account to the URL of a VisualForce page so it looks like this:

apex/AccountSummary?core.apexpages.request.devconsole=1**&id=001D000000JRBes**

Now in the VF page:

<apex:page standardController="Account">
    
    <apex:pageBlock title="Account Summary">
        <apex:pageBlockSection>
        	
            Name: {! Account.Name } <br/>
            Phone: {! Account.Phone } <br/>
            Industry: {! Account.Industry } <br/>
            Revenue: {! Account.AnnualRevenue } <br/>
            
        </apex:pageBlockSection>
    </apex:pageBlock>
    
</apex:page>

So, what is going on here? A whole lot, courtesy of the standard controller!

  1. When the page is loaded, and the <apex:page> component is activated, it activates a standard controller for the account object.
  2. The standard controller sees that there’s an ID parameter in the URL, and searches for and retrieves the matching account record.
  3. The standard controller takes the record and puts it in a variable that it makes available to the page. The variable has the same name as the standard controller’s sObject:  Account. It’s an object variable, and contains all of the fields available on the Account sObject.
  4. The Visualforce expressions all reference the Account variable. They use dot notation to access individual fields within the Account variable. So {! Account.Name }  gets the name of the account, and so on.

Display Fields from Related Records

Use dot notation to display data from related records.

For example, while viewing the object details for Account, you might have noticed that the Account object has a field called Account Owner, and that its type is Lookup(User). In other words, this field has a relationship to a User record. By clicking the Account Owner field label link, you’ll discover its Field Name is Owner.

Account owner: {! Account.Owner.Name } <br/>

The “dot notation” (Account.Owner.Name ) indicates that you want to traverse the relationship between the records. You know that Account.Owner indicates the Owner field of the account record. The extra Name at the end indicates that the owner field isn’t a simple field representing a string, but a relationship to another record (it’s a Lookup(User)), and that you’d like to get the record represented by the value of the Owner field (it’s a User record), and display the Name field on that record.

Standard List Controller

The standard list controller allows you to create Visualforce pages that can display or act on a set of records.

The standard list controller provides many powerful, automatic behaviors such as querying for records of a specific object and making the records available in a collection variable, as well as filtering of and pagination through the results. Adding the standard list controller to a page is very similar to adding the standard (record) controller, but with the intent of working with many records at once, instead of one record at a time.