Standard Controllers

A StandardController object that is automatically provided for standard and all custom objects, bindable to a Visualforce page component with the “standardController” attribute. It provides a reference to a single/list of record to a set of common actions for data processing and default navigation.

What are the tasks of standard controller?

Standard controllers provides ability to access and interact with structured business data contained in records displays in the proper user interface.

Standard controller tasks: controlling data, controlling actions and controlling navigation.

Controlling Data:

Standard controllers fetches data and provide to the views such as page, list, dialog or forms.

Controlling data for a single record: One of the key functionality of standard controllers is to provide the data, and to facilitate binding a view’s controls to the records fields for either display or input. We can associate a standard controller with a visual force page by using “StandardController”  attribute.

<apex:page standardController=”Account”>        // standard object
<apex:page standardController=”customer__c”>    
// custom object

By using merge expressions we can add fields to visualforce pages. This is the same merge syntax used in email templates, formulas and any place that field values need to be merged for expression evaluation. Below highlighted blue color syntax are merge fields

<apex:outputField value="{!Account.Name}"/>
<apex:outputField value="{!Account.AccountNumber}"/>
<apex:inputField value="{!Account.Industry}"/>
<apex:inputField value="{!Account.Type}"/>

See the below syntax to represent represent related parent object fields.

<apex:inputField value="{!Account.Owner.Name}"/>

We can represent a related list in visualforce page by using below syntax.

<apex:relatedList list="Contacts"/>

To view output, after developing your page , you need to pass related sobject record id with your salesforce url. see below example.

https://c.apX.visual.force.com/apex/vfpage?id=XXXXXXXXXXXXXXX

Controlling data for list of records: 

We can manage list of records by using standard controller instruction set. We can define recordsetVar by using below syntax.

<apex:page standardController="Account" recordSetVar="accounts">

Standard controllers provide below additional actions for list of records.

First: Displays the first page of records in the set.

Second: Displays the last page of records in the set.

Next: Displays the next page of records in the set.

Previous: Displays the previous page of records in the set.

Controlling Actions & Navigation:

Actions: Standard controller responds to to user or programmatic commands initiated from a view such as “buttons & custom links.

There are two types of actions available on objects through standard controllers instruction set.

Stateful Actions: Direct binding to a standard controller instance referenced by the page.

Stateless Actions: Indirect binding to the standard controller instruction set of the force.com engine. 

Navigation: Standard Controllers navigate the user to any specific view associate with an action.