※この記事は英語版を翻訳しており、一部に機械翻訳を含むため内容は後日更新される可能性があります。最新の内容は英語版を参照してください。表示言語は画面右下の言語名から切り替えられます。
オブジェクト詳細ページのカスタムボタンまたはリンクから Apex クラスを呼び出すには、Visualforce ページを作成し、アクション属性経由で Apex クラスメソッドを呼び出して動作させます。それを行う方法を示すいくつかのサンプルコードを次に示します。
サーバからこのページが要求されたときに呼び出されるアクションメソッド。式言語を使用してアクションメソッドを参照します。たとえば、action="{!doAction}" は、コントローラ内の doAction() メソッドを参照します。アクションが指定されていない場合は、ページが通常どおりに読み込まれます。アクションメソッドが null を返した場合は、ページが単純に更新されます。このメソッドはページが表示される前に呼び出されるため、オプションで、ユーザを別のページにリダイレクトできます。
重要: このアクションを初期化または DML に使用すべきではありません。
<apex:page standardController="Case" extensions="EscalCase" action="{!caseEscalation}">
<apex:form>
<apex:inputHidden value="{!case.OwnerId}"/>
</apex:form>
</apex:page>
上記の Visualforce ページでは、ケースオブジェクトの標準コントローラを使用し、その機能を拡張します。これにより、ケースレコードの詳細を取得できるようになります。この ID は、デフォルトで Apex クラスからアクセスできできます。示されているように、Apex クラスから非表示項目としてアクセスできるようにする他のすべての値を含める必要があります。<apex:page> 上のアクション属性が apex クラスメソッドを呼び出し、処理を完了します。
public class EscalCase {
//Apex properties or variables
public Id owner {get; set;}
public Id Id { get; set; }
public Case cas { get; set; }
//constructor to get the Case record
public EscalCase(ApexPages.StandardController controller) {
cas = (Case) controller.getRecord();
Id = cas.Id;
System.debug('The case record: ' + cas);
owner = cas.OwnerId;
}
//Method that can is called from the Visual Force page action attribute
public PageReference caseEscalation() {
System.debug('Case Owner: ' + owner);
System.debug('Case Id: ' + Id);
//build your code logic here
PageReference pageRef = new PageReference('/'+Id);
pageRef.setRedirect(true);
return pageRef; //Returns to the case page
}
}
000385214

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.