Dependent fields provide a way to filter the field values displayed on a Visualforce page. Dependent fields consist of two parts: a controlling field that determines the filtering, and a dependent field that has its values filtered. Dependent fields can dynamically filter values in fields such as picklists, multi-select picklists, radio buttons, and checkboxes. Dependent picklists can only be displayed on Visualforce pages with Salesforce API version 19.0 or higher. For more information, see Dependent Picklists in the Salesforce online help.
<apex:page standardController="Account"> <apex:form > <apex:pageBlock mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!save}" value="Save"/> </apex:pageBlockButtons> <apex:pageBlockSection title="Dependent Picklists" columns="2"> <apex:inputField value="{!account.industry}"/> <apex:inputField value="{!account.subcategories__c}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
Pages must include the controlling field for a dependent picklist. Failing to include the controlling field on the page causes a runtime error when the page displays.
<apex:page standardController="Account"> <apex:form> <!-- Don't mix a standard input field... --> <apex:inputField value="{!account.Controlling__c}"/> <apex:outputField value="{!account.Dependent__c}"> <!-- ...with an inline-edit enabled dependent field --> <apex:inlineEditSupport event="ondblClick" /> </apex:outputField> </apex:form> </apex:page>
<apex:form> <!-- other form elements ... --> <apex:outputPanel id="locationPicker"> <apex:outputField value="{!Location.country}"> <apex:inlineEditSupport event="ondblClick" /> </apex:outputField> <apex:outputField value="{!Location.state}"> <apex:inlineEditSupport event="ondblClick" /> </apex:outputField> <apex:outputField value="{!Location.city}"> <apex:inlineEditSupport event="ondblClick" /> </apex:outputField> </apex:outputPanel> <!-- ... --> <apex:commandButton value="Refresh Picklists" reRender="locationPicker" /> </apex:form>