StandardController クラス

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

 

 

1.カスタムObject作成

MyCustomObject__c

 

2.Apexクラス作成

ーーー

public class MyCustomObjectControllerExtension {

private String id;

// The extension constructor initializes the private member
// variable acct by using the getRecord method from the standard
// controller.
public MyCustomObjectControllerExtension(ApexPages.StandardController stdController) {
this.id = stdController.getId();
}

public String getGreeting() {
return 'Hello ' + this.id;
}

}

ーーー

 

 

3.VFページ作成

MyCustomObject.page

ーー

<apex:page standardController="MyCustomObject__c" extensions="MyCustomObjectControllerExtension">
{!greeting} <p/>
<apex:form>
<apex:inputField value="{!MyCustomObject__c.name}"/> <p/>
<apex:commandButton value="Save" action="{!save}"/>
</apex:form>
</apex:page>

ーー

 

 

4.カスタムボタン作成 

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

表示ラベル : RecordSave

名前 : RecordSave

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

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

内容ソース : URL

ーーー

/apex/MyCustomObject?id={!MyCustomObject__c.Id}

ーーー

 

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

 

6.動作確認

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

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

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

xxx/a0D

1)レコード作成する。

MyCustomObject名 : test01

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

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

xxx/apex/MyCustomObject?id=a0D1000001G8DNo

上記のURLが表示される。

f:id:daeheuikim:20180327115336p:plain

入力画面に例えば、test02に変更して「Save」ボタン押下すると、レコードの名前が変更されたことを確認できます。

f:id:daeheuikim:20180327115553p:plain

 

参考URL

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

https://developer.salesforce.com/docs/atlas.ja-jp.apexcode.meta/apexcode/apex_pages_standardcontroller.htm

 

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

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

 

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

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