@salesforce/afv-skills 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/LICENSE.txt +330 -0
  2. package/README.md +466 -0
  3. package/package.json +23 -0
  4. package/skills/apex-class/SKILL.md +253 -0
  5. package/skills/apex-class/examples/AccountDeduplicationBatch.cls +148 -0
  6. package/skills/apex-class/examples/AccountSelector.cls +193 -0
  7. package/skills/apex-class/examples/AccountService.cls +201 -0
  8. package/skills/apex-class/templates/abstract.cls +128 -0
  9. package/skills/apex-class/templates/batch.cls +125 -0
  10. package/skills/apex-class/templates/domain.cls +102 -0
  11. package/skills/apex-class/templates/dto.cls +108 -0
  12. package/skills/apex-class/templates/exception.cls +51 -0
  13. package/skills/apex-class/templates/interface.cls +25 -0
  14. package/skills/apex-class/templates/queueable.cls +92 -0
  15. package/skills/apex-class/templates/schedulable.cls +75 -0
  16. package/skills/apex-class/templates/selector.cls +92 -0
  17. package/skills/apex-class/templates/service.cls +69 -0
  18. package/skills/apex-class/templates/utility.cls +97 -0
  19. package/skills/apex-test-class/SKILL.md +101 -0
  20. package/skills/apex-test-class/references/assertion-patterns.md +209 -0
  21. package/skills/apex-test-class/references/async-testing.md +276 -0
  22. package/skills/apex-test-class/references/mocking-patterns.md +219 -0
  23. package/skills/apex-test-class/references/test-data-factory.md +176 -0
  24. package/skills/deployment-readiness-check/SKILL.md +257 -0
  25. package/skills/deployment-readiness-check/assets/deployment_checklist.md +286 -0
  26. package/skills/deployment-readiness-check/references/rollback_procedures.md +308 -0
  27. package/skills/deployment-readiness-check/scripts/check_metadata.sh +207 -0
  28. package/skills/salesforce-custom-application/SKILL.md +211 -0
  29. package/skills/salesforce-custom-field/SKILL.md +505 -0
  30. package/skills/salesforce-custom-lightning-type/SKILL.md +157 -0
  31. package/skills/salesforce-custom-object/SKILL.md +238 -0
  32. package/skills/salesforce-custom-tab/SKILL.md +78 -0
  33. package/skills/salesforce-experience-site/SKILL.md +178 -0
  34. package/skills/salesforce-flexipage/SKILL.md +445 -0
  35. package/skills/salesforce-flow/SKILL.md +368 -0
  36. package/skills/salesforce-fragment/SKILL.md +42 -0
  37. package/skills/salesforce-lightning-app-build/SKILL.md +254 -0
  38. package/skills/salesforce-list-view/SKILL.md +216 -0
  39. package/skills/salesforce-validation-rule/SKILL.md +72 -0
  40. package/skills/salesforce-web-app-creating-records/SKILL.md +84 -0
  41. package/skills/salesforce-web-app-feature/SKILL.md +70 -0
  42. package/skills/salesforce-web-app-list-and-create-records/SKILL.md +36 -0
  43. package/skills/salesforce-web-application/SKILL.md +34 -0
  44. package/skills/trigger-refactor-pipeline/SKILL.md +191 -0
  45. package/skills/trigger-refactor-pipeline/assets/test_template.apex +321 -0
  46. package/skills/trigger-refactor-pipeline/references/handler_patterns.md +442 -0
  47. package/skills/trigger-refactor-pipeline/scripts/analyze_trigger.py +258 -0
@@ -0,0 +1,505 @@
1
+ ---
2
+ name: salesforce-custom-field
3
+ description: Use this skill when users need to create, generate, or validate Salesforce Custom Field metadata. Trigger when users mention custom fields, field types, Roll-up Summary fields, Master-Detail relationships, Lookup relationships, formula fields, picklists, or field metadata. Also use when users encounter field deployment errors, especially around Roll-up Summary format, Master-Detail constraints, or formula issues. Always use this skill for any custom field metadata work, field generation, or field troubleshooting.
4
+ ---
5
+
6
+ ## When to Use This Skill
7
+
8
+ Use this skill when you need to:
9
+ - Create custom fields on any object
10
+ - Generate field metadata for any field type
11
+ - Set up relationship fields (Lookup or Master-Detail)
12
+ - Create formula or roll-up summary fields
13
+ - Troubleshoot deployment errors related to custom fields
14
+
15
+ # Salesforce Custom Field Generator and Validator
16
+
17
+ ## Overview
18
+
19
+ Generate and validate Salesforce Custom Field metadata with mandatory constraints to prevent deployment errors. This skill has special focus on the **highest-failure-rate field types**: Roll-up Summary and Master-Detail relationships.
20
+
21
+ ## Specification
22
+
23
+ ## 1. Purpose
24
+
25
+ This document defines the mandatory constraints for generating CustomField metadata XML. The agent must verify these constraints before outputting XML to prevent Metadata API deployment errors.
26
+
27
+ **Critical Focus Areas:**
28
+ - Roll-up Summary field format errors
29
+ - Master-Detail field attribute restrictions
30
+ - Lookup Filter restrictions
31
+
32
+ ---
33
+
34
+ ## 2. Universal Mandatory Attributes
35
+
36
+ Every generated field must include these tags:
37
+
38
+ | Attribute | Requirement | Notes |
39
+ |-----------|-------------|-------|
40
+ | `<fullName>` | Required | Derive from `<label>`: capitalize each word, replace spaces with `_`, append `__c`. Must start with a letter. E.g., label `Total Contract Value` → `Total_Contract_Value__c` |
41
+ | `<label>` | Required | The UI name (Title Case) |
42
+ | `<description>` | Mandatory | State the business "why" behind the field |
43
+ | `<inlineHelpText>` | Mandatory | Provide actionable guidance for the end-user. Must add value beyond the label (e.g., "Enter the value in USD including tax" instead of just "The amount") |
44
+
45
+ ### XML Comments — NEVER Before Root Element
46
+
47
+ **NEVER place XML comments (`<!-- ... -->`) before the root `<CustomField>` element in metadata XML files.** Comments between the XML declaration and `<CustomField>` cause a `ConversionError` during deployment. Comments inside the root element are safe.
48
+
49
+ ### External ID Configuration
50
+
51
+ **Trigger:** If the user mentions "integration," "importing data," "external system ID," or "unique key from [System Name]," set `<externalId>true</externalId>`.
52
+
53
+ **Applicable Types:** Text, Number, Email
54
+
55
+ ---
56
+
57
+ ## 3. Technical Interplay: Precision, Scale, and Length
58
+
59
+ To ensure deployment success, follow these mathematical constraints:
60
+
61
+ ### Precision vs. Scale Rules
62
+
63
+ - `precision` is the total digits; `scale` is the decimal digits
64
+ - **Rule:** `precision ≤ 18` AND `scale ≤ precision`
65
+ - **Calculation:** Digits to the left of decimal = `precision - scale`
66
+
67
+ ### The "Fixed 255" Rule
68
+
69
+ For standard TextArea types, the Metadata API requires `<length>255</length>`, even though it isn't configurable in the UI.
70
+
71
+ ### Visible Lines
72
+
73
+ Mandatory for Long/Rich text and Multi-select picklists to control UI height.
74
+
75
+ ---
76
+
77
+ ## 4. Field Data Types
78
+
79
+ ### 4.1 Simple Attribute Types
80
+
81
+ | Type | `<type>` Value | Required Attributes |
82
+ |------|----------------|---------------------|
83
+ | Auto Number | `AutoNumber` | `displayFormat` (must include `{0}`), `startingNumber` |
84
+ | Checkbox | `Checkbox` | Default `defaultValue` to `false` |
85
+ | Date | `Date` | No precision/length required |
86
+ | Date/Time | `DateTime` | No precision/length required |
87
+ | Email | `Email` | Built-in format validation |
88
+ | Lookup Relationship | `Lookup` | `referenceTo`, `relationshipName`, `deleteConstraint` |
89
+ | Master-Detail Relationship | `MasterDetail` | `referenceTo`, `relationshipName`, `relationshipOrder` |
90
+ | Number | `Number` | `precision`, `scale` |
91
+ | Currency | `Currency` | Default precision: 18, scale: 2 |
92
+ | Percent | `Percent` | Default precision: 5, scale: 2 |
93
+ | Phone | `Phone` | Standardizes phone number formatting |
94
+ | Picklist | `Picklist` | `valueSet` with `valueSetDefinition` and `restricted` |
95
+ | Text | `Text` | `length` (Max 255) |
96
+ | Text Area | `TextArea` | `<length>255</length>` |
97
+ | Text (Long) | `LongTextArea` | `length`, `visibleLines` (default 3) |
98
+ | Text (Rich) | `Html` | `length`, `visibleLines` (default 25) |
99
+ | Time | `Time` | Stores time only (no date) |
100
+ | URL | `Url` | Validates for protocol and format |
101
+
102
+ ### 4.2 Computed & Multi-Value Types
103
+
104
+ | Type | `<type>` Value | Required Attributes |
105
+ |------|----------------|---------------------|
106
+ | Formula | Result type (e.g., `Number`) | `formula`, `formulaTreatBlanksAs` |
107
+ | Roll-Up Summary | `Summary` | See Section 6 for complete requirements |
108
+ | Multi-Select Picklist | `MultiselectPicklist` | `valueSet`, `visibleLines` (default 4) |
109
+
110
+ ### 4.3 Specialized Types
111
+
112
+ | Type | `<type>` Value | Required Attributes |
113
+ |------|----------------|---------------------|
114
+ | Geolocation | `Location` | `scale`, `displayLocationInDecimal` |
115
+
116
+ ### Picklist `restricted` Rule
117
+
118
+ The `<restricted>` boolean inside `<valueSet>` controls whether only admin-defined values are allowed.
119
+
120
+ - IF user does not specify → default to `<restricted>true</restricted>` (restricted, avoids performance issues with large picklist value sets)
121
+ - IF user explicitly says the picklist should allow custom/new values, or mentions "unrestricted" or "open" → set `<restricted>false</restricted>`
122
+ - Restricted picklists are limited to 1,000 total values (active + inactive)
123
+
124
+ ```xml
125
+ <valueSet>
126
+ <restricted>true</restricted>
127
+ <valueSetDefinition>
128
+ <sorted>false</sorted>
129
+ <value>
130
+ <fullName>Option_A</fullName>
131
+ <default>false</default>
132
+ <label>Option A</label>
133
+ </value>
134
+ </valueSetDefinition>
135
+ </valueSet>
136
+ ```
137
+
138
+ ---
139
+
140
+ ## 5. Master-Detail Relationship Rules ⭐ CRITICAL
141
+
142
+ Master-Detail fields have **strict attribute restrictions** that differ from Lookup fields. Violating these rules causes deployment failures.
143
+
144
+ ### Forbidden Attributes on Master-Detail Fields
145
+
146
+ **NEVER include these attributes on Master-Detail fields:**
147
+
148
+ | Forbidden Attribute | Why | What Happens |
149
+ |---------------------|-----|--------------|
150
+ | `<required>` | Master-Detail is ALWAYS required by design | Deployment error |
151
+ | `<deleteConstraint>` | Master-Detail ALWAYS cascades deletes | Deployment error |
152
+ | `<lookupFilter>` | Only supported on Lookup fields | Deployment error |
153
+
154
+ ### Master-Detail vs Lookup Comparison
155
+
156
+ | Attribute | Master-Detail | Lookup |
157
+ |-----------|---------------|--------|
158
+ | `<required>` | ❌ FORBIDDEN | ✅ Optional |
159
+ | `<deleteConstraint>` | ❌ FORBIDDEN (always CASCADE) | ✅ Required (`SetNull`, `Restrict`, `Cascade`) |
160
+ | `<lookupFilter>` | ❌ FORBIDDEN | ✅ Optional |
161
+ | `<relationshipOrder>` | ✅ Required (0 or 1) | ❌ Not applicable |
162
+ | `<reparentableMasterDetail>` | ✅ Optional | ❌ Not applicable |
163
+ | `<writeRequiresMasterRead>` | ✅ Optional | ❌ Not applicable |
164
+
165
+ ### ❌ INCORRECT — Master-Detail with forbidden attributes:
166
+
167
+ ```xml
168
+ <CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
169
+ <fullName>Account__c</fullName>
170
+ <label>Account</label>
171
+ <type>MasterDetail</type>
172
+ <referenceTo>Account</referenceTo>
173
+ <relationshipName>Contacts</relationshipName>
174
+ <relationshipOrder>0</relationshipOrder>
175
+ <required>true</required> <!-- WRONG: Remove this -->
176
+ <deleteConstraint>Cascade</deleteConstraint> <!-- WRONG: Remove this -->
177
+ <lookupFilter> <!-- WRONG: Remove this entire block -->
178
+ <active>true</active>
179
+ <filterItems>
180
+ <field>Account.Type</field>
181
+ <operation>equals</operation>
182
+ <value>Customer</value>
183
+ </filterItems>
184
+ </lookupFilter>
185
+ </CustomField>
186
+ ```
187
+
188
+ **Errors:**
189
+ - `Master-Detail Relationship Fields Cannot be Optional or Required`
190
+ - `Can not specify 'deleteConstraint' for a CustomField of type MasterDetail`
191
+ - `Lookup filters are only supported on Lookup Relationship Fields`
192
+
193
+ ### ✅ CORRECT — Master-Detail field:
194
+
195
+ ```xml
196
+ <CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
197
+ <fullName>Account__c</fullName>
198
+ <label>Account</label>
199
+ <description>Links this record to its parent Account</description>
200
+ <type>MasterDetail</type>
201
+ <referenceTo>Account</referenceTo>
202
+ <relationshipLabel>Child Records</relationshipLabel>
203
+ <relationshipName>ChildRecords</relationshipName>
204
+ <relationshipOrder>0</relationshipOrder>
205
+ <reparentableMasterDetail>false</reparentableMasterDetail>
206
+ <writeRequiresMasterRead>false</writeRequiresMasterRead>
207
+ <!-- NO required, deleteConstraint, or lookupFilter -->
208
+ </CustomField>
209
+ ```
210
+
211
+ ### ✅ CORRECT — Lookup field (with optional attributes):
212
+
213
+ ```xml
214
+ <CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
215
+ <fullName>Related_Account__c</fullName>
216
+ <label>Related Account</label>
217
+ <description>Optional link to a related Account</description>
218
+ <type>Lookup</type>
219
+ <referenceTo>Account</referenceTo>
220
+ <relationshipLabel>Related Records</relationshipLabel>
221
+ <relationshipName>RelatedRecords</relationshipName>
222
+ <required>false</required>
223
+ <deleteConstraint>SetNull</deleteConstraint>
224
+ <lookupFilter>
225
+ <active>true</active>
226
+ <filterItems>
227
+ <field>Account.Type</field>
228
+ <operation>equals</operation>
229
+ <value>Customer</value>
230
+ </filterItems>
231
+ <isOptional>false</isOptional>
232
+ </lookupFilter>
233
+ </CustomField>
234
+ ```
235
+
236
+ ### Additional Master-Detail Rules
237
+
238
+ - **Relationship Order:** First Master-Detail on object = `0`, second = `1`
239
+ - **Relationship Name:** Must be a plural PascalCase string (e.g., `Travel_Bookings`)
240
+ - **Junction Objects:** Use two Master-Detail fields for standard many-to-many (enables Roll-ups)
241
+ - **Limit:** Maximum 2 Master-Detail relationships per object. Use Lookup for additional relationships.
242
+
243
+ ---
244
+
245
+ ## 6. Roll-Up Summary Field Rules ⭐ CRITICAL
246
+
247
+ Roll-up Summary fields have the **highest deployment failure rate**. Follow these rules exactly.
248
+
249
+ ### Required Elements for Roll-Up Summary
250
+
251
+ | Element | Requirement | Format |
252
+ |---------|-------------|--------|
253
+ | `<type>` | Required | Always `Summary` |
254
+ | `<summaryOperation>` | Required | `count`, `sum`, `min`, or `max` |
255
+ | `<summaryForeignKey>` | Required | `ChildObject__c.MasterDetailField__c` |
256
+ | `<summarizedField>` | Conditional | Required for `sum`, `min`, `max`. NOT for `count` |
257
+
258
+ ### Forbidden Elements on Roll-Up Summary
259
+
260
+ **NEVER include these attributes on Roll-Up Summary fields:**
261
+
262
+ | Forbidden Attribute | Why |
263
+ |---------------------|-----|
264
+ | `<precision>` | Summary inherits from summarized field |
265
+ | `<scale>` | Summary inherits from summarized field |
266
+ | `<required>` | Not applicable to Summary fields |
267
+ | `<length>` | Not applicable to Summary fields |
268
+
269
+ ### Format Rules for summaryForeignKey and summarizedField
270
+
271
+ **CRITICAL:** Both `summaryForeignKey` and `summarizedField` MUST use the fully qualified format:
272
+
273
+ ```
274
+ ChildObjectAPIName__c.FieldAPIName__c
275
+ ```
276
+
277
+ **Decision Logic:**
278
+ - `summaryForeignKey` = `ChildObject__c.MasterDetailFieldOnChild__c`
279
+ - `summarizedField` = `ChildObject__c.FieldToSummarize__c`
280
+
281
+ ### ❌ INCORRECT — Roll-Up Summary with common errors:
282
+
283
+ ```xml
284
+ <CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
285
+ <fullName>Total_Amount__c</fullName>
286
+ <label>Total Amount</label>
287
+ <type>Summary</type>
288
+ <precision>18</precision> <!-- WRONG: Remove - inherited from source -->
289
+ <scale>2</scale> <!-- WRONG: Remove - inherited from source -->
290
+ <summaryOperation>sum</summaryOperation>
291
+ <summaryForeignKey>Order__c</summaryForeignKey> <!-- WRONG: Missing field name -->
292
+ <summarizedField>Amount__c</summarizedField> <!-- WRONG: Missing object name -->
293
+ </CustomField>
294
+ ```
295
+
296
+ **Errors:**
297
+ - `Can not specify 'precision' for a CustomField of type Summary`
298
+ - `Must specify the name in the CustomObject.CustomField format (e.g. Account.MyNewCustomField)`
299
+
300
+ ### ✅ CORRECT — Roll-Up Summary (SUM operation):
301
+
302
+ ```xml
303
+ <CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
304
+ <fullName>Total_Amount__c</fullName>
305
+ <label>Total Amount</label>
306
+ <description>Sum of all line item amounts</description>
307
+ <inlineHelpText>Automatically calculated from child line items</inlineHelpText>
308
+ <type>Summary</type>
309
+ <summaryOperation>sum</summaryOperation>
310
+ <summarizedField>Order_Line_Item__c.Amount__c</summarizedField>
311
+ <summaryForeignKey>Order_Line_Item__c.Order__c</summaryForeignKey>
312
+ <!-- NO precision, scale, required, or length -->
313
+ </CustomField>
314
+ ```
315
+
316
+ ### ✅ CORRECT — Roll-Up Summary (COUNT operation):
317
+
318
+ ```xml
319
+ <CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
320
+ <fullName>Line_Item_Count__c</fullName>
321
+ <label>Line Item Count</label>
322
+ <description>Count of related line items</description>
323
+ <inlineHelpText>Automatically calculated from child records</inlineHelpText>
324
+ <type>Summary</type>
325
+ <summaryOperation>count</summaryOperation>
326
+ <summaryForeignKey>Order_Line_Item__c.Order__c</summaryForeignKey>
327
+ <!-- NO summarizedField needed for COUNT -->
328
+ <!-- NO precision, scale, required, or length -->
329
+ </CustomField>
330
+ ```
331
+
332
+ ### ✅ CORRECT — Roll-Up Summary (MIN operation):
333
+
334
+ ```xml
335
+ <CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
336
+ <fullName>Earliest_Due_Date__c</fullName>
337
+ <label>Earliest Due Date</label>
338
+ <description>Earliest due date among all line items</description>
339
+ <inlineHelpText>Shows the soonest deadline</inlineHelpText>
340
+ <type>Summary</type>
341
+ <summaryOperation>min</summaryOperation>
342
+ <summarizedField>Order_Line_Item__c.Due_Date__c</summarizedField>
343
+ <summaryForeignKey>Order_Line_Item__c.Order__c</summaryForeignKey>
344
+ </CustomField>
345
+ ```
346
+
347
+ ### ✅ CORRECT — Roll-Up Summary (MAX operation):
348
+
349
+ ```xml
350
+ <CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
351
+ <fullName>Highest_Price__c</fullName>
352
+ <label>Highest Price</label>
353
+ <description>Maximum unit price among all line items</description>
354
+ <inlineHelpText>Shows the most expensive item</inlineHelpText>
355
+ <type>Summary</type>
356
+ <summaryOperation>max</summaryOperation>
357
+ <summarizedField>Order_Line_Item__c.Unit_Price__c</summarizedField>
358
+ <summaryForeignKey>Order_Line_Item__c.Order__c</summaryForeignKey>
359
+ </CustomField>
360
+ ```
361
+
362
+ ### Roll-Up Summary Quick Reference
363
+
364
+ | Operation | summarizedField Required? | Use Case |
365
+ |-----------|---------------------------|----------|
366
+ | `count` | NO | Count number of child records |
367
+ | `sum` | YES | Add up numeric values |
368
+ | `min` | YES | Find smallest value |
369
+ | `max` | YES | Find largest value |
370
+
371
+ ### Roll-Up Summary Prerequisites
372
+
373
+ - Roll-Up Summary fields can ONLY be created on the **parent** object in a Master-Detail relationship
374
+ - The child object MUST have a Master-Detail field pointing to this parent
375
+ - The summarized field must exist on the child object
376
+
377
+ ---
378
+
379
+ ## 7. Formula Field Rules
380
+
381
+ ### Formula Result Types
382
+
383
+ A Formula is not a type itself. The `<formula>` tag is added to a field whose `<type>` is set to the **result data type**:
384
+ - `Checkbox`, `Currency`, `Date`, `DateTime`, `Number`, `Percent`, `Text`
385
+
386
+ ### Formula XML Generation Rules
387
+
388
+ - The contents of the `<formula>` tag MUST be wrapped in a `<![CDATA[ ... ]]>` section. This prevents the XML parser from interpreting formula operators (like `&`, `<`, `>`) as XML markup.
389
+ - If the formula text itself contains the literal sequence `]]>`, escape it by breaking the CDATA block: e.g., `<![CDATA[Text_Field__c & "]]]]><![CDATA[>"]]>`
390
+ - NEVER use an attribute or tag named `returnType`. This does not exist in the Metadata API. The `<type>` tag defines the return data type of the formula result.
391
+
392
+ ### formulaTreatBlanksAs Rule
393
+
394
+ **Decision Logic:**
395
+ - IF formula result type = `Number`, `Currency`, or `Percent` → set `<formulaTreatBlanksAs>BlankAsZero</formulaTreatBlanksAs>`
396
+ - IF formula result type = `Text`, `Date`, or `DateTime` → set `<formulaTreatBlanksAs>BlankAsBlank</formulaTreatBlanksAs>`
397
+
398
+ ### ❌ INCORRECT — Using Formula as type:
399
+
400
+ ```xml
401
+ <CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
402
+ <fullName>Calculated_Value__c</fullName>
403
+ <type>Formula</type> <!-- WRONG: Formula is not a valid type -->
404
+ <returnType>Number</returnType> <!-- WRONG: returnType does not exist in Metadata API -->
405
+ <formula>Field1__c + Field2__c</formula> <!-- WRONG: Missing CDATA wrapper -->
406
+ </CustomField>
407
+ ```
408
+
409
+ ### ✅ CORRECT — Formula field:
410
+
411
+ ```xml
412
+ <CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
413
+ <fullName>Calculated_Value__c</fullName>
414
+ <label>Calculated Value</label>
415
+ <description>Sum of Field1 and Field2</description>
416
+ <type>Number</type> <!-- Result type, not "Formula" -->
417
+ <precision>18</precision>
418
+ <scale>2</scale>
419
+ <formula><![CDATA[Field1__c + Field2__c]]></formula>
420
+ <formulaTreatBlanksAs>BlankAsZero</formulaTreatBlanksAs>
421
+ </CustomField>
422
+ ```
423
+
424
+ ### Formula Field Dependencies
425
+
426
+ Formula fields that reference other fields will fail deployment if the referenced field does not exist or has not been deployed yet. Ensure all referenced fields are deployed before the formula field.
427
+
428
+ ### Specific Function Guidelines
429
+
430
+ | Function | Rule |
431
+ |----------|------|
432
+ | `TEXT()` | MUST NOT be used with Text fields. If the field is already Text, remove the `TEXT()` wrapper. |
433
+ | `CASE()` | Last parameter is always the default value. Total parameter count MUST be even (value-result pairs + default). |
434
+ | `VALUE()` | MUST only be used with Text fields. If a Number is passed as parameter, remove the `VALUE()` wrapper. |
435
+ | `DAY()` | MUST only be used with Date fields. If a DateTime field is used, convert it to Date first (e.g., `DAY(DATEVALUE(DateTimeField__c))`). |
436
+ | `MONTH()` | MUST only be used with Date fields. If a DateTime field is used, convert it to Date first (e.g., `MONTH(DATEVALUE(DateTimeField__c))`). |
437
+ | `DATEVALUE()` | MUST only be used with DateTime fields. If a Date field is used, remove the `DATEVALUE()` wrapper. |
438
+ | `ISPICKVAL()` | MUST be used when checking equality of a Picklist field. NEVER use `==` with Picklist fields. |
439
+ | `ISCHANGED()` | Use `ISCHANGED()` to check if a field value has changed. Do not manually compare with `PRIORVALUE()`. |
440
+
441
+ ---
442
+
443
+ ## 8. Common Deployment Errors
444
+
445
+ | Error Message | Cause | Fix |
446
+ |---------------|-------|-----|
447
+ | `ConversionError: Invalid XML tags or unable to find matching parent xml file for CustomField` | XML comments placed before the root `<CustomField>` element | Remove XML comments (`<!-- ... -->`) that appear before `<CustomField>` in the `.field-meta.xml` file |
448
+ | `Field [FieldName] does not exist. Check spelling.` | Referenced field does not exist or has not been deployed yet | Verify the referenced field exists and is deployed before this field |
449
+ | `DUPLICATE_DEVELOPER_NAME` | Field fullName already exists on the object | Use a unique business-driven name |
450
+ | `MAX_RELATIONSHIPS_EXCEEDED` | More than 2 Master-Detail or 15 Lookup fields on the object | Use Lookup for 3rd+ Master-Detail; review Lookup count |
451
+ | Reserved keyword error | Using `Order__c`, `Group__c`, etc. | Rename to `Status_Order__c`, etc. |
452
+
453
+ ---
454
+
455
+ ## 9. Verification Checklist
456
+
457
+ Before generating CustomField XML, verify:
458
+
459
+ ### Universal Checks
460
+ - [ ] Does `<fullName>` use valid format and end in `__c`?
461
+ - [ ] Are `<description>` and `<inlineHelpText>` both populated and meaningful?
462
+ - [ ] Is `<label>` in Title Case?
463
+ - [ ] Are there no XML comments (`<!-- ... -->`) before the root `<CustomField>` element? (Comments before the root element break SDR's parser)
464
+
465
+ ### Master-Detail Field Checks ⭐ CRITICAL
466
+ - [ ] Is `<required>` attribute ABSENT? (Master-Detail is always required)
467
+ - [ ] Is `<deleteConstraint>` attribute ABSENT? (Master-Detail always cascades)
468
+ - [ ] Is `<lookupFilter>` block ABSENT? (Only for Lookup fields)
469
+ - [ ] Is `<relationshipOrder>` set to `0` or `1`?
470
+ - [ ] Is parent object's `<sharingModel>` set to `ControlledByParent`?
471
+
472
+ ### Lookup Field Checks
473
+ - [ ] Is `<deleteConstraint>` set to `SetNull`, `Restrict`, or `Cascade`?
474
+ - [ ] Is `<relationshipName>` in plural PascalCase?
475
+
476
+ ### Roll-Up Summary Field Checks ⭐ CRITICAL
477
+ - [ ] Is `<precision>` attribute ABSENT?
478
+ - [ ] Is `<scale>` attribute ABSENT?
479
+ - [ ] Is `<summaryForeignKey>` in format `ChildObject__c.MasterDetailField__c`?
480
+ - [ ] For SUM/MIN/MAX: Is `<summarizedField>` in format `ChildObject__c.FieldName__c`?
481
+ - [ ] For COUNT: Is `<summarizedField>` ABSENT?
482
+ - [ ] Does the child object have a Master-Detail field to this parent?
483
+
484
+ ### Formula Field Checks
485
+ - [ ] Is `<type>` set to result type (NOT "Formula")?
486
+ - [ ] Is `<formula>` content wrapped in `<![CDATA[ ... ]]>`?
487
+ - [ ] Is `<returnType>` attribute ABSENT? (does not exist in Metadata API)
488
+ - [ ] Is `<formulaTreatBlanksAs>` set to `BlankAsZero` for numeric results or `BlankAsBlank` for text/date results?
489
+ - [ ] Do all referenced fields exist and deploy before this field?
490
+
491
+ ### Numeric Field Checks
492
+ - [ ] Is `scale ≤ precision`?
493
+ - [ ] Is `precision ≤ 18`?
494
+
495
+ ### Text Area Checks
496
+ - [ ] For TextArea: Is `<length>255</length>` explicitly included?
497
+ - [ ] For LongTextArea/Html: Is `<visibleLines>` set?
498
+
499
+ ### Relationship Limit Checks
500
+ - [ ] Are there 2 or fewer Master-Detail relationships on the object?
501
+ - [ ] Are there 15 or fewer Lookup relationships on the object?
502
+
503
+ ### Naming Checks
504
+ - [ ] Is the API name free of reserved words (`Order`, `Group`, `Select`, etc.)?
505
+ - [ ] Is the API name unique on this object?
@@ -0,0 +1,157 @@
1
+ ---
2
+ name: salesforce-custom-lightning-type
3
+ description: Use this skill when users need to create Custom Lightning Types (CLTs) for Einstein Agent actions or structured input/output schemas. Trigger when users mention CLT, Custom Lightning Types, JSON schemas for agents, type definitions, lightning__objectType, or editor/renderer configurations. This is complex - always use this skill for CLT work.
4
+ ---
5
+
6
+ ## When to Use This Skill
7
+
8
+ Use this skill when you need to:
9
+ - Create Custom Lightning Types (CLTs) for structured inputs/outputs
10
+ - Generate JSON Schema-based type definitions for Lightning Platform
11
+ - Configure CLTs for Einstein Agent actions
12
+ - Set up editor and renderer configurations for custom UI
13
+ - Troubleshoot deployment errors related to Custom Lightning Types
14
+
15
+ ## Specification
16
+
17
+ # CustomLightningType Metadata Specification
18
+
19
+ ## Overview & Purpose
20
+ Custom Lightning Types (CLTs) are JSON Schema-based type definitions used by the Lightning Platform (including Einstein Agent actions) to describe structured inputs/outputs and drive editor/renderer experiences.
21
+
22
+ ## Configuration
23
+ - **Choose standard Lightning types** when the structure is simple and can be expressed with properties and supported primitive `lightning:type` identifiers.
24
+ - **Choose Apex class types** (`@apexClassType/...`) when the structure already exists server-side and you want the Apex class to define the shape.
25
+ - **Include editor/renderer config** only when you need custom UI behavior (custom LWC input/output components). Otherwise, omit.
26
+
27
+ ## Critical Rules (Read First)
28
+ - **Root object schemas MUST include**:
29
+ - `"type": "object"`
30
+ - `"title"`
31
+ - `"lightning:type": "lightning__objectType"`
32
+ - `"unevaluatedProperties": false`
33
+ - `"unevaluatedProperties"` is enforced as `false` by the CLT metaschema. Do not set it to `true`.
34
+ - **Root object schemas MUST NOT include** `"examples"` when `"unevaluatedProperties": false` is set.
35
+ - **Nested objects (inside `properties`) MUST NOT set** `"lightning:type": "lightning__objectType"`.
36
+ - Nested objects should be plain JSON Schema objects (`type`, `properties`, optional `required`, optional `unevaluatedProperties`).
37
+ - **List/array properties are highly restricted by the CLT metaschema**:
38
+ - **CRITICAL LIMITATION**: the CLT metaschema may reject the `items` keyword entirely. Treat `items` as **disallowed by default**.
39
+ - **Root-level arrays** (direct children of the root `properties`):
40
+ - **MUST include** `"lightning:type": "lightning__listType"`
41
+ - **MUST NOT include** `"items"`
42
+ - **OPTIONAL** `"type": "array"`
43
+ - **Nested arrays** (arrays inside nested objects) are the most common failure:
44
+ - **MUST include** `"type": "array"`
45
+ - **MUST NOT include** `"lightning:type": "lightning__listType"`
46
+ - **MUST NOT include** `"items"`
47
+ - **When `"unevaluatedProperties": false` is set, any unknown keyword will fail validation**. Prefer removing keywords over relaxing strictness.
48
+ - **Apex class CLTs are minimal**:
49
+ - Include **only** `title`, `description` (optional), and `lightning:type` set to `@apexClassType/...`.
50
+ - Do **not** add `type`, `properties`, `required`, or `unevaluatedProperties`.
51
+
52
+ ## Additional CLT Metaschema Validations
53
+ - **Org namespace validation**: titles/descriptions and other string fields may be validated to ensure you are not using an org namespace in places that are disallowed.
54
+ - **Lightning type validation**: CLTs are validated to prevent referencing internal namespaces (for example, disallowing types from internal namespaces like `sfdc_cms` where not permitted).
55
+ - **Object type validation**: the CLT root is validated to ensure `lightning:type` is exactly `lightning__objectType`.
56
+
57
+ ## Primitive Types & Constraints
58
+ - `lightning__textType`
59
+ - Max length 255
60
+ - `lightning__multilineTextType`
61
+ - Max length 2000
62
+ - `lightning__richTextType`
63
+ - Max length 100000
64
+ - `lightning__urlType`
65
+ - Max length 2000
66
+ - Optional `lightning:allowedUrlSchemes` enum values: `https`, `http`, `relative`, `mailto`, `tel`
67
+ - `lightning__dateType`
68
+ - Data pattern: YYYY-MM-DD
69
+ - `lightning__timeType`
70
+ - Data pattern: HH:MM:SS.sssZ
71
+ - `lightning__dateTimeType`
72
+ - Data shape is an object with required `dateTime` and optional `timeZone`
73
+ - `lightning__numberType`
74
+ - Decimal numbers; optional `maximum`, `minimum`, `multipleOf`
75
+ - `lightning__integerType`
76
+ - Whole numbers only; optional `maximum`, `minimum`
77
+ - `lightning__booleanType`
78
+ - true/false
79
+
80
+ ## Allowed Property-Level Keywords
81
+ When strict validation is enabled (`unevaluatedProperties: false`), keep each property minimal and prefer only keywords known to be allowed:
82
+ - `title`, `description`, `einstein:description`
83
+ - `type` (when used, ensure it matches the chosen `lightning:type`)
84
+ - `lightning:type`
85
+ - `maximum`, `minimum`, `multipleOf` (numeric)
86
+ - `maxLength`, `minLength` (string)
87
+ - `const`, `enum`
88
+ - `lightning:textIndexed`, `lightning:supportsPersonalization`, `lightning:localizable`
89
+ - `lightning:uiOptions`, `lightning:allowedUrlSchemes`
90
+ - `lightning:tags` (metaschema restricts values; currently `flow` is the only known allowed tag)
91
+
92
+ ## Generation Workflow
93
+ 1. **Confirm the CLT approach**
94
+ - If referencing Apex: capture the exact class reference (`@apexClassType/namespace__ClassName$InnerClass`).
95
+ - If using standard primitives: list the fields, their Lightning primitive types, and which fields are required.
96
+ 2. **Draft `schema.json`**
97
+ - Start with the root object structure (required root fields).
98
+ - Add `properties` using valid primitive `lightning:type` identifiers.
99
+ - For nested objects: omit `lightning:type` and keep keywords minimal.
100
+ - For arrays: follow the strict list rules (avoid `items`; avoid `lightning:type` on nested arrays).
101
+ 3. **(Optional) Draft `editor.json`** (only if custom UI is required)
102
+ - **Supported shape:** Top-level `editor` object with `editor.componentOverrides` and `editor.layout`.
103
+ - Top-level `editor` object.
104
+ - Use `editor.componentOverrides` for component overrides.
105
+ - Use `editor.layout` for layout.
106
+ - **Root override pattern** (most common for fully custom editing UI):
107
+ - `editor.componentOverrides["$"] = { "definition": "c/<yourEditorComponent>", "attributes": { ... } }`
108
+ - When passing schema data into a custom LWC, use attribute mapping with the `{!$attrs.<name>}` syntax: e.g. `"attributes": { "myField": "{!$attrs.value}" }` so the runtime binds schema values to your component's attributes.
109
+ - **Property-level override pattern** (for individual fields):
110
+ - `editor.componentOverrides["<propertyName>"] = { "definition": "es_property_editors/<...>" }`
111
+ - **Valid editor components** (examples): `es_property_editors/inputText`, `es_property_editors/inputNumber`, `es_property_editors/inputRichText`, `es_property_editors/inputImage`, `es_property_editors/inputTextarea`. **Do not use** `es_property_editors/inputList`.
112
+ - **Collection editor** (for root-level `lightning__listType` properties): Use a collection-level override so the list is edited by a custom component: `collection.editor.componentOverrides["$"] = { "definition": "c/<yourCollectionEditorComponent>" }`. Alternatively, use `editor.layout` with `lightning/propertyLayout` and `attributes.property = "<listPropertyName>"` for default list editing.
113
+ - **Layout pattern**:
114
+ - `editor.layout.definition = "lightning/verticalLayout"`
115
+ - `editor.layout.children[*].definition = "lightning/propertyLayout"` with `attributes.property = "<propertyName>"`
116
+ - **Avoid known-invalid patterns**:
117
+ - Do not use `es_property_editors/inputList`.
118
+ - Do not use `itemSchema` attributes.
119
+ 4. **(Optional) Draft `renderer.json`** (only if custom UI is required)
120
+ - **Supported shape:** Top-level `renderer` object with `renderer.componentOverrides` and `renderer.layout`.
121
+ - Top-level `renderer` object.
122
+ - Use `renderer.componentOverrides` for component overrides.
123
+ - Use `renderer.layout` for layout.
124
+ - **Root override pattern** (most common for fully custom rendering UI):
125
+ - `renderer.componentOverrides["$"] = { "definition": "c/<yourRendererComponent>", "attributes": { ... } }`
126
+ - Use `{!$attrs.<name>}` in attribute mappings when binding schema data to custom renderer component attributes.
127
+ - **Property-level override pattern**:
128
+ - `renderer.componentOverrides["<propertyName>"] = { "definition": "es_property_editors/outputText" | "es_property_editors/outputNumber" | "es_property_editors/outputImage" | ... }`. **Valid renderer components** (examples): `es_property_editors/outputText`, `es_property_editors/outputNumber`, `es_property_editors/outputImage`. Avoid input-style components in the renderer.
129
+ - **Collection renderer** (for root-level `lightning__listType` properties): Use `collection.renderer.componentOverrides["$"] = { "definition": "c/<yourListRendererComponent>" }` or `es_property_editors/genericListTypeRenderer` to render the list.
130
+ 5. **Place files in the correct bundle structure**
131
+ - `lightningTypes/<TypeName>/schema.json`
132
+ - (Optional) `lightningTypes/<TypeName>/lightningDesktopGenAi/editor.json`
133
+ - (Optional) `lightningTypes/<TypeName>/lightningDesktopGenAi/renderer.json`
134
+ - For Gen AI / Copilot the standard path is `lightningDesktopGenAi/`. Other targets (e.g. Experience Builder, Mobile Copilot, Enhanced Web Chat) use different subfolders when supported: `experienceBuilder/`, `lightningMobileGenAi/`, `enhancedWebChat/`.
135
+ 6. **Deploy and validate**
136
+ - Deploy the bundle using your org's standard metadata deployment flow (e.g. Salesforce CLI or IDE). The MCP client or tooling in use should provide or integrate with the appropriate deploy/retrieve commands for Lightning Type bundles.
137
+ - Validate incrementally: if deployment fails, remove disallowed keywords first (especially `examples`, `items`, nested `lightning:type`).
138
+
139
+ ## Common Deployment Errors
140
+ | Error / Symptom | Likely Cause | Fix |
141
+ |---|---|---|
142
+ | Schema validation fails due to unknown keyword | `unevaluatedProperties: false` + disallowed keyword (commonly `examples`, `items`) | Remove the offending keyword; keep schema minimal |
143
+ | Nested object validation failure | Nested object includes `lightning:type: lightning__objectType` | Remove `lightning:type` from nested objects |
144
+ | Array property rejected | Use of `items` (or `lightning:type` in nested arrays) rejected by validator | For nested arrays: keep only `type: "array"`. For root arrays: use minimal structure; remove `items` if rejected |
145
+ | Apex-based CLT rejected | Extra fields added (e.g., `type`, `properties`) | Use only `title`, optional `description`, and `lightning:type` |
146
+ | Editor config rejected | Use of invalid patterns (`es_property_editors/inputList`, `itemSchema`) or unrecognized top-level keys | Use `editor.componentOverrides` and `editor.layout`; keep config minimal |
147
+
148
+ ## Verification Checklist
149
+ - [ ] Root schema has `type: "object"`, `title`, `lightning:type: "lightning__objectType"`, and `unevaluatedProperties: false`
150
+ - [ ] Root schema does not include `examples` when strict validation is enabled
151
+ - [ ] No nested object includes `lightning:type: "lightning__objectType"`
152
+ - [ ] Arrays are defined minimally (especially nested arrays)
153
+ - [ ] Only supported primitive `lightning:type` identifiers are used for leaf properties
154
+ - [ ] Apex class CLTs contain only `title`/`description` and `lightning:type: "@apexClassType/..."`
155
+ - [ ] Bundle structure and filenames match Lightning Types requirements
156
+ - [ ] Editor config uses only allowed patterns (no `es_property_editors/inputList`, no `itemSchema`); use valid components (e.g. `es_property_editors/inputText`, `es_property_editors/inputNumber`) or custom `c/` components
157
+ - [ ] Renderer config uses output-style components (e.g. `es_property_editors/outputText`, `es_property_editors/outputNumber`) where applicable, not input editors