function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
gaisergaiser 

Picklist InputField does not respect RecordType?

Hi,

I have an object (Item__c) with picklist Status__c and two record types RT1,RT2
Status__c picklist is single-select and has following values: Value1, Value2,Value3
In record type settings I have
RT1: Value1 - the only value available for Status__c
RT2: Value2 - the only value available for Status__c

In my custom controller I preset Item__c.RecordTypeId in constructor such as when page is rendered I display RecordTypeId value as well as Status__c picklist as input value.

 
Code:
...
<apex:outputText value="{!Item__c.RecordTypeId}"/>
<apex:inputField value="{!Item__c.Status__c}"/>
...

 I expected that list of available values in Status__c picklist will be rendered according to the RecordType settings, i.e. if I set RecordTypeId=<ID-of-RT1> then  Status__c will display Value1 *only*.
But in reality it displays all values and also ignores Default value setting based on Record Type.
I am certain that RecordTypeId is set correctly because I can see it on the screen.

Am I doing something wrong and <apex:inputField> supposed to respect RecordType Settings or is it by design.
If by design, then what is the best way to display picklist values based on RecordType settings?

jwetzlerjwetzler
InputField does not currently support recordTypes, but it is on the roadmap.
gaisergaiser
Many thanks for clarification, really helpful.
jeffdonthemicjeffdonthemic
Jill,

Any idea when this might be implemented? We currently have 400+ recordtypes and the fact that inputField do not support recordTypes severely limits our use of Visualforce page. We've had to revert back to S-Controls in some cases.

Thanks
Jeff Douglas
Informa Plc
ForceNoobForceNoob

I saw this documentation but still not getting it right.

 

Displaying Record Types

Visualforce pages with a Salesforce.com API version equal to or greater than 20.0 support record types. Record types allow you to offer different business processes, picklist values, and page layouts to different users based on their profiles.

After creating a record type in Setup, enabling support for it in Visualforce requires no additional actions on your part. Visualforce pages for objects that use record types respect your settings. Record typefield is namedRecordTypeId.

Your record typedefinitions affect the rendering of<apex:inputField>tags in the following ways:
  • If the<apex:inputField>tag refers to a picklist field that's filtered by a record type:
    • The rendered<apex:inputField>component only displays options compatible with that record type.
    • If the<apex:inputField>component is bound to a dependent picklist with a rendered and editable controlling field, only options compatible with both the record type and the controlling field value display.
  • If the<apex:inputField>tag refers to a record typefield:
    • If the user can change the field’s record type, or select a record typefor the new field, the<apex:inputField>component renders as a drop-down list. Otherwise, it renders as read-only text.
    • It's the developer's responsibility to either refresh the page or rerender filtered picklists when the list changes. (figured out this is what i'm missing)
In addition, the<apex:outputField>tag's support for record typesis identical to a read-only implementation of the<apex:inputField>behavior.

When overriding the New button with a Visualforce page, you also have the option to skip the record type selection page. If selected, any new records you create won't be forwarded to the record type selection page, since it assumes that your Visualforce page is already handling record types.