Tuesday, October 9, 2012

Picklist field and field dependencies in Force.com

Picklist field is a drop-down list. Unlike the simple text field, picklist field consists of predefined values and these appear as options to select for the user. Force.com platform allows you to define 2 types of picklists. 1. Standard Picklist - User can select a single value from the drop-down list. 2. Multi-Select Picklist - User can select one or more values at a time.

In Force.com platform, while adding a new custom field to an object you select the data type as 'Picklist' to create a new Standard Picklist. Or select data type as 'Picklist (Multi-Select)' to create a new Multi-Select Picklist. Then the steps that follow will guide you how to define the list of values for drop-down list, specify the sort order and default value if any. In case of multi-select, you can also specify how many lines should be visible in the scrollable box that is displayed for the user.

Many times there are scenarios where you want to group the related values in different fields and make them dependent on each other rather than displaying all of them in one lengthy drop-down. For example, instead of listing all countries in one single field you may want to give the user a field to select a continent first  and then based on the selected continent you would list the countries belonging to that continent. Thus making the country drop-down list a readable list.

In Force.com platform, this is achieved by field dependencies. Under the custom fields section of an object, there is a button 'Field Dependencies'. This is for setting up the kind of fields we just talked above. 

For example, after adding the Continent and Countries as custom field of type Picklist, you setup the field dependencies. While setting up the field dependencies, you specify the 'Controlling Field' and 'Dependent Field'. Controlling field is the one that filters the options in the other field that is specified as dependent. In this example, you would specify Continent as controlling and Country as dependent. After you specify these 2, the next step will allow you to organize the dependencies just by few clicks on the predefined values for the picklists. You can even preview your picklists. 

Setting up picklists and dependencies in Force.com platform simple and easy. Give it a try!

Happy cloud computing using Salesforce!