ちょっとUSのForce.com Blogで面白そうな記事がありました。
Apex UI Buttonsと言うタイトルの記事です。
翻訳しながら読んでみました。
詳細ページのカスタムボタンからApexコードを実行するのは、JavaScriptと
Ajaxツールキットでできるけど、Visualforceページでも実装できるよ。
という話のようです。
わかりやすいサンプルソース付きでした。
■クラス側(ApexButtonPageController)
public class ApexButtonPageController {
Account theAccount;
public ApexButtonPageController(ApexPages.StandardController stdController{
//get the current Account
theAccount = (Account)stdController.getRecord();
} public PageReference doMyApexLogic() {
//whatever logic you want
//<demo logic>
theAccount.Industry = 'Spice Trading';
update theAccount;
//</demo logic>
return new PageReference('/' + theAccount.id);
}
}
■ページ側(ApexButtonPage)
<apex:page standardController="Account" extensions="ApexButtonPageController" action="{!doMyApexLogic}" />
手順
- Apexクラス作成
- Visualforceページ作成
- 取引先にカスタムボタン作成
・表示の種類:詳細ページボタン
・動作:現在のウィンドウにサイドバーおよびヘッダーなしで表示
・内容のソース:Visualforceページ - 取引先詳細画面にボタンを表示
- ボタンをクリックすると業種項目に値がセットされます。
今までこんな感じの機能はJavascript経由で作成していたので、勉強になりました。
それからページとクラスを作成ですが、開発者コンソールから作成する方法で
説明されています。
開発者コンソールからページ、クラスの作成もなかなか面白かったです。
Force.com Blogの記事のURLは次のとおりです。
http://blogs.developerforce.com/developer-relations/2012/11/apex-ui-buttons.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+SforceBlog+%28Force.com+Blog%29