Newer Version Available
AccountCreator インターフェース
Chatter アンサーユーザと関連付けられる取引先レコードを作成します。
名前空間
使用方法
ChatterAnswers.AccountCreator は、chatteranswers:registration Visualforce コンポーネントの registrationClassName 属性で指定されます。このインターフェースは Chatter アンサーによってコールされます。また、このインターフェースでは、ポータルユーザが使用する取引先レコードをカスタム作成できます。
ChatterAnswers.AccountCreator インターフェースを実装するには、最初に implements キーワードでクラスを次のように宣言する必要があります。
1public class ChatterAnswersRegistration implements ChatterAnswers.AccountCreator {次に、クラスで次のメソッドの実装を提供する必要があります。
1public String createAccount(String firstname, String lastname, Id siteAdminId) {
2 // Your code here
3}実装されたメソッドは global または public として宣言する必要があります。
AccountCreator の実装例
これは、ChatterAnswers.AccountCreator インターフェースの実装例です。createAccount メソッドの実装では、ユーザ情報を受け取り、取引先レコードを作成します。メソッドは、取引先 ID の String 値を返します。
1swfobject.registerObject("clippy.codeblock-2", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17public class ChatterAnswersRegistration implements ChatterAnswers.AccountCreator {
18 public String createAccount(String firstname, String lastname, Id siteAdminId) {
19 Account a = new Account(name = firstname + ' ' + lastname, ownerId = siteAdminId);
20 insert a;
21 return a.Id;
22 }
23}この例では、上記のコードをテストします。
1swfobject.registerObject("clippy.codeblock-3", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17@isTest
18private class ChatterAnswersCreateAccountTest {
19 static testMethod void validateAccountCreation() {
20 User[] user = [SELECT Id, Firstname, Lastname from User];
21 if (user.size() == 0) { return; }
22 String firstName = user[0].FirstName;
23 String lastName = user[0].LastName;
24 String userId = user[0].Id;
25 String accountId = new ChatterAnswersRegistration().createAccount(firstName, lastName, userId);
26 Account acct = [SELECT name, ownerId from Account where Id =: accountId];
27 System.assertEquals(firstName + ' ' + lastName, acct.name);
28 System.assertEquals(userId, acct.ownerId);
29 }
30}