,

Picklists

You have no doubt seen a picklist in action—one of those drop-down lists that provide a selection of valid values. The Force.com platform picklist data type allows you to specify the values for the picklist and displays the object in the appropriate user interface.

Picklist Usage

There are several places in your application that cry out for picklists to guide your users to correct data values.

In the Position object, these fields require only a limited set of values:

  • Department - departments in Universal Containers

  • Education - levels of educational attainment

  • Status - progress of the position towards being filled

The Candidate object also has an opportunity for a picklist

  • Education -specifies the maximum level of education for this candidate

In addition to these basic picklists, which will limit the user selection to a single value from a list of values, the Position object also contains a different type of picklist, one that limits the selection of values for a user, but allows the user to select more than one value. You can use this type of functionality for a picklist that lists all the programming languages required for a particular technical position.

Adding Picklists

As you might have noticed when defining fields in the previous chapters, the picklist option is available as a data type for fields.

1.
Go to the Builder area for the Position object by clicking Setup Create Objects Position.

2.
Click New in the Custom Fields & Relationships section.

3.
Select Picklist as the data type and click Next to bring up the page shown, in a completed state, below.



Figure 44. Defining a picklist


4.
Set the Field Label to Department and add the following values in the text area, each on a separate line:

  • Engineering

  • Finance

  • IT

  • Sales

  • Support

Voice of the Developer

The values you are adding are the labels that will be displayed in your picklist. You can change these labels without affecting the stored value for individual records. For instance, if you want to change the name of the Support department to Customer Support, you simply change the value for the picklist, and the values displayed for every record also change.

5.
After entering the values for the picklist in the text box, specify whether the values are displayed in alphabetical order and whether the first value is the default for the field. Select the checkbox to sort values alphabetically, since that will probably make it easier for the user to find the right department. If you do not choose to specify a default value, the field does not have a value. Later in this chapter, you learn how to create a validation to require a value for this picklist.

6.
Accept the default Field Name of Department, give the field an appropriate description and help text, and click Next.

7.
Accept the default field level security and click Next.

8.
Accept the default placement in the Position Layout and click Save & New, since you want to add more picklists for this object.

9.
Add two more picklists for the Position object with the following attributes:

Name/LabelValuesAlphabeticalDefault
Educational RequirementsHigh school

College

Masters

PhD

Post-doc
NoNo
StatusNew

Open

Closed
NoYes

10.
After adding the picklists, click the Positions tab, and click New to see the newly revised appearance, as shown below.



Figure 45. Your revised entry page for Position


The picklists look just as you had hoped. The Candidate object could use a picklist, but since you already understand how to use the Field Creation Wizard to make picklists, you can just follow the instructions in the Code Share project for this book to add the Education picklist to the Candidate object, since you will need that picklist to define a formula field later in this chapter. The Education picklist has the same values as the Educational Requirements picklist for the Position object.

Voice of the Developer

You can edit picklists while the field is in production, but you should be aware of the potential implications of this action.

If you delete a picklist value, existing records with fields containing this value will be unaffected. The platform does not invalidate the data entries so that you can later decide what value should take its place in these records. You can replace the value with the Replace link next to a given picklist field.

If you choose to edit a pick list value, the platform will update existing records with the new value for you; however, if you have written Apex code (covered in Chapters 10 and 11) that references this value, the code will not be modified, which, depending on the implementation, can potentially cause run-time errors. For this reason, best practices suggest careful consideration of picklist values before releasing any applications into the wild.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.208.203