StandardSetController クラス

以下はStandardSetController クラスのSampleです。

 

 

1.カスタムObject作成

MyCustomObject__c

 

 

2.Apexクラス作成

ーーー

public class MyCustomObjectSetControllerExtension {
// ApexPages.StandardSetController must be instantiated
// for standard list controllers
public ApexPages.StandardSetController setCon {
get {
if(setCon == null) {
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
[SELECT Name FROM MyCustomObject__c]));
}
return setCon;
}
set;
}

// Initialize setCon and return a list of records
public List<MyCustomObject__c> getMyCustomObjects() {
return (List<MyCustomObject__c>) setCon.getRecords();
}
}

 

 

3.VFページ作成

MyCustomObjectSet.page

ーー

<apex:page controller="MyCustomObjectSetControllerExtension">
<apex:pageBlock>
<apex:pageBlockTable value="{!myCustomObjects}" var="c">
<apex:column value="{!c.Name}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>

ーー

 

 

4.カスタムボタン作成 

※カスタムObjectのカスタムボタン作成

表示ラベル : RecordListView

名前 : RecordListView

表示の種類 : 詳細ページボタン

動作 : 新規ウィドウに表示

内容ソース : URL

ーーー

/apex/MyCustomObjectSet

ーーー

 

5.ページレイアウトにカスタムボタン表示

 

6.動作確認

カスタムObjectのレコード一覧へ移動

SalesforceのIdはEclipseの「Salesforce.schema」でPrefix確認できます。

例えば、Prefixが「a0D」の場合には、「Home」ボタン押下して、URLの後ろに以下を追加する。

xxx/a0D

1)レコード作成する。

MyCustomObject名 : test02、test03

2)レコード詳細画面表示

3)カスタムボタン「RecordListView」押下する。

f:id:daeheuikim:20180327122432p:plain

 

参考URL

カスタムObjectのSetコントローラのコントラクタ作成

https://developer.salesforce.com/docs/atlas.ja-jp.pages.meta/pages/apex_pages_standardsetcontroller.htm

 

カスタムボタンのVisualforce呼び出す

http://deferloader.blog.uhuru.co.jp/?p=331

 

カスタムボタンのパラメータ

https://help.salesforce.com/articleView?id=defining_custom_links_fields.htm&type=5