StandardController クラス
標準コントローラの拡張を定義する場合は、StandardController を使用します。
名前空間
ApexPages
使用方法
StandardController オブジェクトは、Salesforce が提供する、開発済みの Visualforce コントローラを参照します。StandardController オブジェクトを参照する必要があるのは、標準コントローラの拡張を定義する場合のみです。StandardController は、拡張クラスコンストラクタの単一引数のデータ型です。
インス��ンス化
次の方法で、StandardController をインスタンス化することができます。
1ApexPages.StandardController sc = new ApexPages.StandardController(sObject);例
次の例では、StandardController オブジェクトの標準コントローラ拡張のコンストラクタでの使用方法を示します。
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}次の Visualforce マークアップは、上記のコントローラ拡張をページ内で使用する方法を示します。
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>