---
schema_version: "1"
id: cea1d0fe2c9bed3b51222c1ff8b4208e2f8c461b2e0ec16116e141cc1f061144
title: AccountCreator Interface
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_interface_chatteranswers_accountcreator.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_interface_chatteranswers_accountcreator.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 7e278f12e246af9ed597892214af6804453680d526ea7b5086698e05099feec1
description: Creates Account records that will be associated with Chatter Answers users.Accepts basic user information and creates an Account record. The implementation of this method returns the account ID.
---
# AccountCreator Interface

Creates Account records that will be associated with Chatter Answers users.

## Namespace

[ChatterAnswers](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_namespace_ChatterAnswers.htm "The ChatterAnswers namespace provides an interface for creating Account records.")

## 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:

public with sharing class ChatterAnswersRegistration implements ChatterAnswers.AccountCreator {

Next, your class must provide an implementation for the following method:

public String createAccount(String firstname, String lastname, Id siteAdminId) {
    // Your code here
}

The implemented method must be declared as global or public.

- **[AccountCreator Methods](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_interface_chatteranswers_accountcreator.htm#apex_ChatterAnswers_AccountCreator_methods)**
- **[AccountCreator Example Implementation](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_interface_chatteranswers_accountcreator.htm#apex_interface_chatteranswers_accountcreator_example)**

## AccountCreator Methods

The following are methods for AccountCreator.

- **[createAccount(firstName, lastName, siteAdminId)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_interface_chatteranswers_accountcreator.htm#apex_ChatterAnswers_AccountCreator_createAccount)**  
    Accepts basic user information and creates an Account record. The implementation of this method returns the account ID.

### 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

- **firstName**:
    
    Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")
    
    The first name of the user who is registering.
- **lastName**:
    
    Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")
    
    The last name of the user who is registering.
- **siteAdminId**:
    
    Type: [ID](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_id.htm#apex_methods_system_id "Contains methods for the ID primitive data type.")
    
    The user ID of the Site administrator, used for notification if any exceptions occur.

#### Return Value

Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")

## 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.

public with sharing class ChatterAnswersRegistration implements ChatterAnswers.AccountCreator {
    public String createAccount(String firstname, String lastname, Id siteAdminId) {
         Account a = new Account(name = firstname + ' ' + lastname, ownerId = siteAdminId);
         insert as user a;
         return a.Id;
    }
}

This example tests the code above.

@IsTest
private with sharing class ChatterAnswersCreateAccountTest {
    @IsTest
    static void validateAccountCreation() {
        User\[\] user = \[SELECT Id, Firstname, Lastname from User WHERE UserType='Standard' WITH USER\_MODE\];
        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 WITH USER\_MODE\];
        Assert.areEqual(firstName + ' ' + lastName, acct.name);
        Assert.areEqual(userId, acct.ownerId);
  }
}