You need to sign in to do that
Don't have an account?

error creating a Person Account in a custom controller
I am creating an online application that will dump into a Person Account. However when I try to instanciate the account obj in the getter I get the following runtime validation error:
Validation Errors While Saving Record(s) There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Student Record Type: value not valid for the entity: Account".
Here's the VF page
<apex:page showHeader="false" controller="newStudentApplicationController" > <apex:sectionHeader title="Application" subtitle="Page 1 of 5"/> <apex:form > <apex:pageBlock title="Student Application" mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!save}" value="Save"/> <apex:commandButton action="{!cancel}" value="Cancel" onclick="return confirmCancel()" immediate="true"/> </apex:pageBlockButtons> <apex:pageBlockSection title="General Information"> <apex:inputfield id="studentTitle" value="{!student.salutation}"/> <apex:inputfield id="studentFirstName" value="{!student.firstName}"/> <apex:inputfield id="studentLastName" value="{!student.lastname}"/> <apex:inputfield id="studentBirthdate" value="{!student.personBirthdate}"/> <apex:inputfield id="studentAffiliation" value="{!student.Affiliation__pc}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
Here is the Controller
public class newStudentApplicationController { // Object Variable Account student; // Getters public Account getStudent() { if(student == null) { RecordType recType = [select id,name,sobjectType,ispersontype from recordType where ispersontype=true and sobjectType='account' limit 1]; // student = new Account(recordtypeid=recType.id); student = new Account(); } return student; }
If I try using the default constructor (commented out line above), I this error:
Validation Errors While Saving Record(s) There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Student Record Type: value not valid for the entity: PersonAccount".
I have a feeling I am missing somethign small. Any help would be GREATLY Appreciated.
Thanks!
This isn't your full code. Two things I'd do, one to fix your issue, the other to modularize your code better. First, to fix your issue make sure all profiles using this page have access to the RecordTypes you've defined for the Account object. When you set up the record type, you are given the option to enable for all or select profiles. you probably missed it for one or more profiles.
The second thing I'd do is move your selection of a recordtype into a utility, rather than querying for it in-line and in a getter. If your code gets to any reasonable level of complexity, this will be an important encapsulation technique
Gtuerk, thanks for the response. I am currently working in DE and all off my profiles have the Person Account record type enabled and not only that but it is the only record type enabled. Also I am working with a system admin profile, so if that was the issue it should still have worked for me, no?
You are correct, this is not my full code as the rest is somewhat irrelevant as it is just the save method, which has yet to be called and since this was a runtime issue, not a compiler issue, I didn't think it was necessary. If you want to see it, I can show you.
Thanks for the using the util tip. Any other ideas of the problem?
Here is the controller again