+ Start a Discussion

how to add custom picklists and multi-select picklists to VF page with a custom controller?

I noticed when trying to add a custom field to a VF page using a custom controller when the field is of type picklist or m-s picklist, I get the validation error Record Type ID: not valid entry for Account.


On the examples I saw, it looked like using inputfield should work, except the examples were using standard picklists not custom.


Is there a quick easy way to add the picklist to the page, or am I going to have to create a selectlist, and in the controller create a List with the values pulled via SOQL? If I have several picklists, is there an efficient way to query to avoid any govenor limits issues?


Here's the page:

The Gender, Country of Birth are Picklists, Citizenship is a Mulit-select Picklist



<apex:page showHeader="false" controller="studentApplicationController" >
<apex:sectionHeader title="Student Application" subtitle="Page 1 of 5"/>
<apex:form >
<apex:pageBlock title="General and Contact Information" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save"/>
<apex:commandButton action="{!cancel}" value="Cancel"
onclick="return confirmCancel()" immediate="true"/>

<p>Salutation:&nbsp; <apex:inputtext id="studentSalutation" value="{!salutation}"/></p>
<p>First Name:&nbsp; <apex:inputtext id="studentFirstName" value="{!firstName}"/></p>
<p>Last Name:&nbsp; <apex:inputtext id="studentLastName" value="{!lastname}"/></p>
<p>Date of Birth:&nbsp; <apex:inputfield id="studentBirthdate" value="{!student.personBirthdate}"/></p>
<p>Gender:&nbsp; <apex:inputfield id="studentGender" value="{!student.Gender__pc}"/></p>
             <p>Citizenship:&nbsp; <apex:inputfield id="studentCitizenship" value="{!student.Citizenship__pc}"/></p>
             <p>Country of Birth:&nbsp; <apex:inputfield id="studentCoB" value="{!student.County_of_Birth__pc}"/></p>

<p>Social Security, Social Insurance, or similar Government ID Number:&nbsp; <apex:inputfield id="studentForeignId" value="{!student.Social_Security__pc}"/><br />
Passport Number:&nbsp; <apex:inputfield id="studentPassport" value="{!student.Passport_Foreign__pc}"/></p>
<p>Driver License Number:&nbsp; <apex:inputfield id="studentDLN" value="{!student.Drivers_License__pc}"/></p>
<p>Driver License State:&nbsp; <apex:inputfield id="studentDLS" value="{!student.Drivers_License_State__pc}"/></p>
<p>Did you serve in the I.D.F.?&nbsp; <apex:inputfield id="studentIDF" value="{!student.IDF__pc}"/></p>

<h2>Contact Information</h2>
<p>Current Street Address:&nbsp; <apex:inputfield id="studentCurrentStreet" value="{!student.billingStreet}"/></p>
<p>Current City:&nbsp; <apex:inputfield id="studentCurrentCity" value="{!student.billingCity}"/></p>
<p>Current State/Province:&nbsp; <apex:inputfield id="studentCurrentSoP" value="{!student.billingState}"/></p>
<p>Current Zipcode/Postal Code:&nbsp; <apex:inputfield id="studentCurrentZoPC" value="{!student.billingPostalCode}"/></p>
<p>Current Country:&nbsp; <apex:inputfield id="studentCurrentCountry" value="{!student.billingCountry}"/></p>
<p>Phone Number:&nbsp; <apex:inputfield id="studentPhone" value="{!student.personHomePhone}"/></p>
<p>Cell Number:&nbsp; <apex:inputfield id="studentCell" value="{!student.personMobilePhone}"/></p>
<p>Fax:&nbsp; <apex:inputfield id="studentFax" value="{!student.fax}"/></p>
<p>Email:&nbsp; <apex:inputfield id="studentEmail" value="{!student.personEmail}"/></p>
<p>Second Email:&nbsp; <apex:inputfield id="studentEmail2" value="{!student.X2nd_Email__pc}"/></p>


Here is the Controller:



 public with sharing class studentApplicationController {

    // Non-Object VF Fields
    public String lastname { get; set; }
    public String firstName { get; set; }
    public String salutation { get; set; }

    // Object Variable
    Account student;
    Date__c startdate;
    RelativeContact__c spouse;
    RelativeContact__c father;
    RelativeContact__c mother;
    List<Educational_Institution__c> schools;
    // Other Variables
    String cancelPageURL = 'https://c.cs0.visual.force.com/apex/StudentApplicationPage1';
    String submittedPageURL = 'https://c.cs0.visual.force.com/apex/StudentApplicationPage1';
    // 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); 
        return student;
    public Date__c getStartDate() {
        if(startdate == null) {
            startdate = new Date__c(status__c='Entered - Non-Academic');
        return startdate;
    public RelativeContact__c getSpouse() {
        if(spouse == null)
            spouse = new RelativeContact__c();
        return spouse;
    public RelativeContact__c getFather() {
        if(spouse == null)
            spouse = new RelativeContact__c();
        return spouse;
    public RelativeContact__c getMother() {
        if(spouse == null)
            spouse = new RelativeContact__c();
        return spouse;
    // Page References for Navigation
    public PageReference page1() {
      return Page.StudentApplicationPage1;

    // If applicant cancels, redirect to cancel page
    public PageReference cancel() {
        PageReference cancelPage = new PageReference(cancelPageURL);
        return cancelPage; 
    // Save the application into Salesforce
    public PageReference save() {
        student.lastname = lastname;
        student.firstname = firstname;
        student.salutation = salutation;
        insert student;
        startdate.student__c = student.id;
        insert startdate;
        PageReference submittedPage = new PageReference(submittedPageURL);
        return submittedPage;