Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
AccountCreator Interface
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.
1public class ChatterAnswersRegistration implements ChatterAnswers.AccountCreator {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)
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 WHERE UserType='Standard'];
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}