Is it possible to programmatically create a record type in Apex to be used in a test?


2 Answers 2


No, it's not possible to create RecordTypes from Apex, since RecordType doesn't support DML.

It's likely possible to achieve your ends some other way - for example, see this answer to a similar question.


Create a record type manually like this:

  1. Setup -> Customize -> Accounts -> Record Types
  2. Click 'new'.
  3. Specify your record type.
  4. Click save.

Assign to a user the permission to view and assign a record type:

  1. Setup -> Manage Users -> Profiles -> choose a profile
  2. Under the category: "Record Type Settings" choose edit field, next to Accounts.
  3. Under "Available record types" select your record type.
  4. Press 'Add' to add the record type to the selected record types.
  5. Specify a default record type, click Save.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .