# Critical XML Rules & Deployment Errors ## Contents 0. [STOP — Read Before Writing ANY componentInstance](#stop--read-before-writing-any-componentinstance) 1. [Property Value Encoding](#1-property-value-encoding-most-common-error) 2. [Field References](#2-field-references) 3. [Region vs Facet Types](#3-region-vs-facet-types) 4. [itemInstances — ONE Child Per Wrapper](#4-iteminstances--one-child-per-wrapper-critical) 5. [Unique Identifiers and Region Names](#5-unique-identifiers-and-region-names-critical---prevents-duplicate-errors) 6. [Correct Element Names](#6-correct-element-names-critical--prevents-invalid-xml-errors) 7. [Common Deployment Errors](#common-deployment-errors) --- ## STOP — Read Before Writing ANY componentInstance **The element name is ``, NEVER ``.** ```xml label Hello flexipage:fieldSection id1 label Hello flexipage:fieldSection id1 ``` **There is no `` element in FlexiPage XML. It does not exist. Every time you write a property inside ``, you MUST write ``. If you find yourself typing ``, STOP and correct it to ``.** --- ## 1. Property Value Encoding (MOST COMMON ERROR) **Any property value with HTML/XML characters MUST be manually encoded in the following order** (wrong order causes double-encoding corruption): ```text 1. & → & (FIRST! Encode this before others) 2. < → < 3. > → > 4. " → " 5. ' → ' ``` **Wrong:** ```xml Important text ``` **Correct:** ```xml <b>Important</b> text ``` **Check your XML:** Search for `` tags - they should never contain raw `<` or `>` characters. ## 2. Field References Use `Record.{FieldApiName}` — never `{ObjectName}.{FieldApiName}` (Salesforce resolves from Record, not object name). ```xml Record.Name Account.Name ``` ## 3. Region vs Facet Types **Template Regions** (header, main, sidebar): ```xml header Region ``` **Component Facets** (internal slots like fieldSection columns): ```xml Facet-12345 Facet ``` **Rule:** If it's a template region name → `Region`. If it's a component slot → `Facet`. ## 4. itemInstances — ONE Child Per Wrapper (CRITICAL) **Each `` can contain exactly ONE child element** — either one `` OR one ``. Never put multiple children inside a single ``. ```xml flexipage:field field1 flexipage:field field2 flexipage:field field1 flexipage:field field2 ``` ### fieldInstance Structure Every fieldInstance requires: ```xml uiBehavior none Record.FieldName__c RecordFieldName_cField ``` **Valid `uiBehavior` values (lowercase only):** | Value | Meaning | |-------|---------| | `none` | Field respects standard editability settings (default) | | `readonly` | Field is permanently locked on this page | | `required` | Field must be filled out before saving on this page | **Rules:** - Each `` gets exactly ONE child (`` or ``) - fieldInstance must have `fieldInstanceProperties` with `uiBehavior` - Use `Record.{Field}` format - There is NO `edit` value — use `none` for standard editable fields ## 5. Unique Identifiers and Region Names (CRITICAL - PREVENTS DUPLICATE ERRORS) **EVERY identifier and region/facet name MUST be unique across the entire FlexiPage file.** - **NEVER create two `` blocks with the same ``** - **If multiple components belong to same facet, combine them in ONE region with multiple ``** - **NEVER reuse the same `` value** - **Always read entire file first and extract ALL existing identifiers and names** - **Element order inside ``**: `` FIRST, then `` (if needed), then ``, then `` — NEVER put ``/`` before `` **Wrong - This WILL FAIL with duplicate name error:** ```xml flexipage_property_details_fieldSection ... detailTabContent Facet flexipage_pricing_fieldSection ... detailTabContent Facet ``` **Correct - Combine itemInstances in ONE region:** ```xml flexipage_property_details_fieldSection ... flexipage_pricing_fieldSection ... detailTabContent Facet ``` **When to combine vs separate:** - **Combine**: Components that logically belong to same tab/section (e.g., multiple field sections in detail tab) - **Separate**: Components that belong to different tabs/sections (e.g., `detailTabContent` vs `relatedTabContent`) --- ## 6. Correct Element Names (CRITICAL — PREVENTS INVALID XML ERRORS) **FlexiPage XML uses specific element names. Common LLM hallucinations use WRONG names that cause deployment failures.** | WRONG (do NOT use) | CORRECT | |---|---| | `` | `` | | `` | `` | | `` | `` | | `` | `` | | `` | (does not exist — use facets for nesting) | | `` | `` containing `` | | `` | `` | | `flexipage:templateName` | `flexipage__default_rec_L` | **Do NOT invent elements or component names:** Only use component names discovered through the 3-tier discovery process or present in the template from CLI. Do NOT add any XML element that is not present in the template structure from the CLI template. If a component name did not come from discovery or the CLI template. | WRONG (do NOT use) | Why / What to use instead | |---|---| | `` | Not a FlexiPage element — API version lives in `sfdx-project.json` | | `` | Not a FlexiPage element — use `` for the page name | | `flexipage:tabs` | Does not exist — use `flexipage:tabset` + `flexipage:tab` in facets | | `flexipage:tabset2` | Does not exist — correct name is `flexipage:tabset` | | `flexipage:facet` | Does not exist — use `flexipage:column` with `body` property | | `flexipage:fields` | Does not exist — use individual `fieldInstance` elements in a field facet | | `String` inside `componentInstanceProperties` | Remove — only valid `` value is `decorator`, and only for UtilityBar pages | **Correct top-level FlexiPage structure (element order):** ```xml ... Page Name flexipage__default_rec_L Account RecordPage ``` **Correct componentInstance structure:** ```xml propertyName propertyValue lightning:card unique_id_1 ``` **`` children — ``, ``, and optionally ``:** ```xml fieldApiName String Record.Name fieldApiName Record.Name panelHeight decorator 480 ``` **`` rules:** - If omitted (default): the property applies to the Lightning component itself - If `decorator`: the property applies to the **component decorator** (a wrapper that adds capabilities like height/width when opened) - The ONLY valid value is `decorator` — never `String`, `Facet`, `Integer`, etc. - Component decorators are ONLY supported on **UtilityBar** page types — do NOT use `decorator` on RecordPage, AppPage, or HomePage **Nesting is done via facets, NOT via inner elements.** Components that contain other components reference a facet name in their properties; the facet is a sibling `` with `Facet`. | Error | Cause | Fix | |-------|-------|-----| | "Element regions invalid in FlexiPage" | Used `` instead of `` | Replace with `` | | "Element components invalid in FlexiPageRegion" | Used `` instead of `` | Replace with `` | | "couldn't retrieve design time component information" | Used hallucinated component name (`flexipage:tabs`, `flexipage:tabset2`) | Use `flexipage:tabset` — see `identifiers_and_regions.md` for the full 3-layer tab pattern | --- ## Common Deployment Errors | Error | Cause | Fix | |-------|-------|-----| | "We couldn't retrieve or load the information on the field" | Invalid field API name — field doesn't exist or has incorrect spelling | Use MCP tools or describe commands to discover valid fields | | "Invalid field reference" | Used `ObjectName.Field` instead of `Record.Field` | Change to `Record.{FieldApiName}` | | "Element componentInstance is duplicated at this location in type ItemInstance" | Multiple `` in one `` | Each `` needs its own `` wrapper | | "Element fieldInstance is duplicated" | Multiple fieldInstances in one `` | Each fieldInstance needs its own `` wrapper | | "Missing fieldInstanceProperties" | No uiBehavior specified | Add `fieldInstanceProperties` with `uiBehavior` | | "Unused Facet" | Facet defined but not referenced by any component | Remove Facet or reference it in a component property | | "XML parsing error" | Unencoded HTML/XML in property values | Encode `<`, `>`, `&`, `"`, `'` in all `` tags | | "Cannot create component with namespace" | Invalid page name (used `__c` suffix) | Use `Volunteer_Record_Page` not `Volunteer__c_Record_Page` | | "Region specifies mode that parent doesn't support" | Added `` to a region that doesn't support it | Only use `` where required (e.g., `Replace` in `detailTabContent` for Dynamic Forms) | | "We couldn't retrieve the design time component information for component X" | Hallucinated component name (e.g., `flexipage:tabs`, `flexipage:tabset2`) | Use correct component name — see Section 6 table and `identifiers_and_regions.md` for valid patterns | | "'String' is not a valid value for the enum 'ComponentInstancePropertyTypeEnum'" | Used invalid `` value (e.g., `String`, `Facet`, `Integer`) inside `` | Remove `` entirely — the only valid value is `decorator`, and only for UtilityBar page types | | "Element apiVersion invalid at this location in type FlexiPage" | Added `` to FlexiPage XML | Remove — API version belongs in `sfdx-project.json`, not in FlexiPage metadata |