Apex StandardSetController クラスの使い方のサンプル
環境
Salesforce
構文
1.ApexPages.StandardSetControllerのオブジェクトの初期化
ApexPages.StandardSetController setCon = new ApexPages.StandardSetController(Database.getQueryLocator( [SELECT Name, CloseDate FROM Opportunity]));
StandardSetController クラスには、プロトタイプオブジェクトも含まれます。
2.Visualforce マークアップでコントローラの情報を表示します
<apex:pageBlockTable value="{!opportunities}" var="変数名">
<apex:column value="{!変数名.Name}"/>
操作例
1.StandardSetController オブジェクトのカスタムリストコントローラのコンストラクタの定義
public class opportunityListInfo {
// ApexPages.StandardSetControllerをインスタンス化する
//標準リストコントローラー set get
public ApexPages.StandardSetController setCon {
get {
if(setCon == null) {
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
[SELECT Name, CloseDate FROM Opportunity]));
}
return setCon;
}
set;
}
// setConを初期化し、レコードのリストを返す
public List<Opportunity>getOpportunities() {
return (List<Opportunity)setCon.getRecords();
}
}
2.コントローラをページ内で使用する
<apex:page controller="opportunityListInfo">
<apex:pageBlock>
<apex:pageBlockTable value="{!opportunities}" var="op">
<apex:column value="{!op.Name}"/>
<apex:column value="{!op.CloseDate}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>