StandardController Class

Use a StandardController when defining an extension for a standard controller.




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.


You can instantiate a StandardController in the following way:
ApexPages.StandardController sc = new ApexPages.StandardController(sObject);


The following example shows how a StandardController object can be used in the constructor for a standard controller extension:

public class myControllerExtension {

    private final Account acct;
    // The extension constructor initializes the private member
    // variable acct by using the getRecord method from the standard
    // controller.
    public myControllerExtension(ApexPages.StandardController stdController) { this.acct = (Account)stdController.getRecord(); } public String getGreeting() { return 'Hello ' + + ' (' + + ')'; } }

The following Visualforce markup shows how the controller extension from above can be used in a page:

<apex:page standardController="Account" extensions="myControllerExtension">
    {!greeting} <p/>
        <apex:inputField value="{!}"/> <p/>
        <apex:commandButton value="Save" action="{!save}"/>
© Copyright 2000–2015, inc. All rights reserved.
Various trademarks held by their respective owners.