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.
public class ChatterAnswersRegistration implements ChatterAnswers.AccountCreator {
public String createAccount(String firstname, String lastname, Id siteAdminId) { // Your code here }
The implemented method must be declared as global or public.
The following are methods for AccountCreator.
public String createAccount(String firstName, String lastName, Id siteAdminId)
Type: String
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.
public class ChatterAnswersRegistration implements ChatterAnswers.AccountCreator { public String createAccount(String firstname, String lastname, Id siteAdminId) { Account a = new Account(name = firstname + ' ' + lastname, ownerId = siteAdminId); insert a; return a.Id; } }
This example tests the code above.
@isTest private class ChatterAnswersCreateAccountTest { static testMethod void validateAccountCreation() { User[] user = [SELECT Id, Firstname, Lastname from User]; if (user.size() == 0) { return; } String firstName = user[0].FirstName; String lastName = user[0].LastName; String userId = user[0].Id; String accountId = new ChatterAnswersRegistration().createAccount(firstName, lastName, userId); Account acct = [SELECT name, ownerId from Account where Id =: accountId]; System.assertEquals(firstName + ' ' + lastName, acct.name); System.assertEquals(userId, acct.ownerId); } }