# Advanced Picklist Reference Detailed rules and worked examples for picklist CustomFields that go beyond a simple inline value list. All XML uses the `http://soap.sforce.com/2006/04/metadata` namespace with a `` root, exactly like the simple-picklist examples in the main skill. Covered here: 1. [Value Set References (``)](#1-value-set-references-valuesetname) 2. [Controlling / Dependent Picklists](#2-controlling--dependent-picklists) 3. [Enhanced Value Attributes (`color`, `isActive`, value-level ``)](#3-enhanced-value-attributes) 4. [Picklist Validation Rules](#4-picklist-validation-rules) 5. [Scoping a Picklist to a Record Type](#5-scoping-a-picklist-to-a-record-type) --- ## 1. Value Set References (``) A picklist field can either define its values **inline** or **reference an existing value set** (a Global Value Set or a Standard Value Set). The shared set is defined once and reused across many fields. ### ⭐ HARD RULE: `` is EITHER a reference OR inline — never both A `` element must contain **exactly one** of: - `` — references an existing value set (this section), **OR** - `` — defines values inline (the simple-picklist case). Including both in the same `` is a deployment error. #### ❌ INCORRECT — both reference and inline definition: ```xml Priority__c Picklist true Priority_Levels false High false ``` **Error:** `Value set must reference a value set name or define a value set, but not both.` #### ✅ CORRECT — reference a Global Value Set: ```xml Priority__c Account priority drawn from the shared Priority Levels value set Select the priority defined by the central Priority Levels list Picklist true Priority_Levels ``` ### Same `` element — Global vs. Standard value sets The SAME `` element is used to reference both kinds of value set; only the name you put inside it differs. | Referenced set | `` value | Suffix | |----------------|------------------------|--------| | **StandardValueSet** (platform-defined, e.g. Industry, LeadSource) | Bare enum name | NO `__c`, NO `__gvs` → `Industry` | | **GlobalValueSet** | Bare developer name | NO `__c`, **NO `__gvs`** → `Priority_Levels` | > **Rule: always use the bare developer name — never add `__gvs`.** In API 57.0+ orgs the > platform stores/displays a GlobalValueSet's name with a `__gvs` suffix internally, but the > **Metadata API (deploy AND retrieve) uses the bare name** (the suffix came from a patched-out > Winter '23 change that broke deploys). So `Priority_Levels`, never > `Priority_Levels__gvs`. A retrieve showing `__gvs` (or a "returned from org but not found in > local project" warning) is expected org-storage display — keep local metadata on the bare name. > Never append `__c` to a value-set name either. #### ✅ CORRECT — reference a Standard Value Set (bare name, no suffix): ```xml Industry__c Industry classification from the standard Industry value set Pick the industry that best describes this account Picklist true Industry ``` ### A value-set-backed field is `` by design When a field references a value set, its values can only change by editing the value set itself — the field cannot define ad-hoc values. Set `true` on these fields. Leaving it unrestricted is meaningless for a referenced set. ### Cross-reference: creating the value set itself This skill only **references** an existing value set. **Creating** the GlobalValueSet or editing a StandardValueSet (the `.globalValueSet-meta.xml` / `.standardValueSet-meta.xml` metadata) is the job of the `platform-value-set-generate` skill. If the value set does not yet exist, generate it there first, then reference it here. --- ## 2. Controlling / Dependent Picklists A **dependent** picklist filters its available values based on the selected value of a **controlling** field (another picklist, or a checkbox). The dependency lives on the **dependent** field via a `` element plus one `` block per (controlling value → dependent value) pair. ### ⭐ Use the MODERN API 38.0+ form ONLY | Form | Elements | Status | |------|----------|--------| | **Modern (API 38.0+)** | `` → `` + `` + `` (`` + ``) | ✅ USE THIS | | **Legacy (API ≤ 37.0)** | `` / `` / `` | ❌ DEPRECATED — do NOT generate | Never emit the legacy ``, ``, or `` tags. They are not valid against the modern Metadata API and will fail deployment. ### ⭐ HARD RULE: both the controlling and dependent field must be `true` A field dependency requires a fixed, admin-defined value set on **both** ends. **Always emit `true` inside the `` of the controlling field AND the dependent field** — even when the request does not mention "restricted". Omitting it produces an unrestricted picklist, which cannot reliably participate in a field dependency and diverges from the expected metadata. This is non-negotiable for dependent picklists: if you write a `` or ``, the same `` must also carry `true`. ### Structure of a dependent picklist Inside the dependent field's ``, in this order: 1. `` — API name of the controlling field (e.g. `Country__c`). 2. `` — defines the dependent field's own values (as usual). The dependency mapping does **NOT** go in here. 3. one or more `` blocks — **siblings** of ``, NOT nested inside it or inside any ``. One block **per (controlling value, dependent value) pair**: - `` — a controlling-field value that enables this dependent value. - `` — the dependent value that becomes available. > ### ⛔ THE #1 MISTAKE: do NOT put `` inside `` > The mapping lives in **separate `` blocks**, never as a child of a > `` in ``. Putting `` inside a `` > fails deployment with `Element controllingFieldValue invalid at this location in type CustomValue`. > > ```xml > > > > USAfalse > Americas > > > > > > USAfalse > > > Americas > USA > > ``` > > **One `` per pair.** With multiple controlling values (Americas→USA,Canada; > EMEA→UK,Germany) you emit **one block for each (controllingValue, dependentValue) pair** — four > pairs = four `` blocks. And remember: both fields carry `true`. ### ✅ CORRECT — State dependent on Country (USA → California, Texas) **Controlling field — `Country__c` (a plain restricted picklist):** ```xml Country__c Country used to filter the dependent State picklist Select the country first; the State list filters to match Picklist true false USA false Canada false ``` **Dependent field — `State__c`, controlled by `Country__c`:** ```xml State__c State filtered by the selected Country Available states depend on the Country you picked Picklist Country__c true false California false Texas false USA California USA Texas ``` > Each dependent value gets its own `` block per enabling controlling > value. If California were also valid under a second country, you would add another > `` block with that country's `` and > `California`. ### ❌ INCORRECT — deprecated legacy form: ```xml State__c Picklist Country__c California USA ``` **Error:** `Element {http://soap.sforce.com/2006/04/metadata}picklist is not allowed` — the legacy dependency elements are not valid in the modern `` structure. --- ## 3. Enhanced Value Attributes ### ⭐ Value-name fidelity — do NOT underscore picklist value names A **picklist value's `` is NOT a field API name** and must NOT be transformed. Use the value text **exactly as the user spelled it**, spaces and all. A value the user calls `Closed Won` is `Closed Won` and `` — **never** `Closed_Won`. Picklist value `` permits spaces (and is not required to carry `__c`); the space-to-underscore + `__c` rule applies ONLY to the **field** `` (e.g. field `Total Contract Value` → `Total_Contract_Value__c`), not to the values inside it. Underscoring a value name changes the value's identity, diverges from what the user asked for, and breaks any RecordType `` / `` that reference the value by its real name. | Element | Spaces? | `__c` suffix? | Example for "Closed Won" | |---|---|---|---| | **Field** `` | ❌ replace with `_` | ✅ required | (field named) `Status__c` | | **Picklist value** `` | ✅ keep as written | ❌ never | `Closed Won` | | **Picklist value** `