+ Start a Discussion

How To Test Account Insert With RecordType ID Being Set

Hi,   I have a Force.com site in which the Standard Record Type Settings of the Account within my Site settings ensures that when I create an account through my site it is created using the RecordType as specified in "Standard Record Type Settings"


If I want to test this though in my test class I will need to set the RecordTypeID in my insert to the Account object.  This does not seem possible as I get errors similar to the following 


Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, entity type cannot be inserted: Person Account: []


I have previously detailed this error in http://boards.developerforce.com/t5/Apex-Code-Development/Insert-record-to-Account-object-with-RecordType-set/m-p/458977#M83914  but my workaround does not include Test Classes.


Does anyone know if there is a way of setting the RecordTypeID when creating an Account so that I can add such a RecordTypeID to my test class?


Thanks in advance.

Best Answer chosen by Admin (Salesforce Developers) 



Please make sure the System.runAs(User) have appropriate permission for creating account records with the record type that you have mentioned.


Mark it as resolved if it helps you.