Newer Version Available
AccountCreator Interface
Creates Account records that will be associated with Chatter Answers users.
Namespace
Usage
The ChatterAnswers.AccountCreator is specified in the registrationClassName attribute of a chatteranswers:registration Visualforce component. This interface is called by Chatter Answers and allows for custom creation of Account records used for portal users.
To implement the ChatterAnswers.AccountCreator interface, you must first
declare a class with the implements keyword as follows:
1public class ChatterAnswersRegistration implements ChatterAnswers.AccountCreator {Next, your class must provide an implementation for the following
method:
1public String createAccount(String firstname, String lastname, Id siteAdminId) {
2 // Your code here
3}The implemented method must be declared as global or public.
AccountCreator Methods
The following are methods for AccountCreator.
createAccount(firstName, lastName, siteAdminId)
Accepts basic user information and creates an Account record.
The implementation of this method returns the account ID.
Signature
public String createAccount(String firstName, String lastName, Id siteAdminId)
Parameters
Return Value
Type: String
AccountCreator Example Implementation
This is an example implementation of the ChatterAnswers.AccountCreator interface. The createAccount method implementation accepts user information and creates an Account record. The method returns a String value for the Account ID.
1public class ChatterAnswersRegistration implements ChatterAnswers.AccountCreator {
2 public String createAccount(String firstname, String lastname, Id siteAdminId) {
3 Account a = new Account(name = firstname + ' ' + lastname, ownerId = siteAdminId);
4 insert a;
5 return a.Id;
6 }
7}This example tests the code above.
1@isTest
2private class ChatterAnswersCreateAccountTest {
3 static testMethod void validateAccountCreation() {
4 User[] user = [SELECT Id, Firstname, Lastname from User];
5 if (user.size() == 0) { return; }
6 String firstName = user[0].FirstName;
7 String lastName = user[0].LastName;
8 String userId = user[0].Id;
9 String accountId = new ChatterAnswersRegistration().createAccount(firstName, lastName, userId);
10 Account acct = [SELECT name, ownerId from Account where Id =: accountId];
11 System.assertEquals(firstName + ' ' + lastName, acct.name);
12 System.assertEquals(userId, acct.ownerId);
13 }
14}