Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
StandardController Class
Namespace
ApexPages
Usage
StandardController objects reference the pre-built Visualforce controllers provided by Salesforce. The only time it is necessary to refer to a StandardController object is when defining an extension for a standard controller. StandardController is the data type of the single argument in the extension class constructor.
Instantiation
1ApexPages.StandardController sc = new ApexPages.StandardController(sObject);Example
The following example shows how a StandardController object can be used in the constructor for a standard controller extension:
1public class myControllerExtension {
2
3 private final Account acct;
4
5 // The extension constructor initializes the private member
6 // variable acct by using the getRecord method from the standard
7 // controller.
8 public myControllerExtension(ApexPages.StandardController stdController) {
9 this.acct = (Account)stdController.getRecord();
10 }
11
12 public String getGreeting() {
13 return 'Hello ' + acct.name + ' (' + acct.id + ')';
14 }
15}The following Visualforce markup shows how the controller extension from above can be used in a page:
1<apex:page standardController="Account" extensions="myControllerExtension">
2 {!greeting} <p/>
3 <apex:form>
4 <apex:inputField value="{!account.name}"/> <p/>
5 <apex:commandButton value="Save" action="{!save}"/>
6 </apex:form>
7</apex:page>