Loading...
Loading...
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.
npx skill4agent add forcedotcom/afv-library generating-custom-field| Attribute | Requirement | Notes |
|---|---|---|
| Required | Derive from |
| Required | The UI name (Title Case) |
| Mandatory | State the business "why" behind the field |
| 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") |
<externalId>true</externalId>precisionscaleprecision ≤ 18scale ≤ precisionprecision - scale<length>255</length>| Type | | Required Attributes |
|---|---|---|
| Auto Number | | |
| Checkbox | | Default |
| Date | | No precision/length required |
| Date/Time | | No precision/length required |
| Built-in format validation | |
| Lookup Relationship | | |
| Master-Detail Relationship | | |
| Number | | |
| Currency | | Default precision: 18, scale: 2 |
| Percent | | Default precision: 5, scale: 2 |
| Phone | | Standardizes phone number formatting |
| Picklist | | |
| Text | | |
| Text Area | | |
| Text (Long) | | |
| Text (Rich) | | |
| Time | | Stores time only (no date) |
| URL | | Validates for protocol and format |
| Type | | Required Attributes |
|---|---|---|
| Formula | Result type (e.g., | |
| Roll-Up Summary | | See Section 6 for complete requirements |
| Multi-Select Picklist | | |
| Type | | Required Attributes |
|---|---|---|
| Geolocation | | |
restricted<restricted><valueSet><restricted>true</restricted><restricted>false</restricted><valueSet>
<restricted>true</restricted>
<valueSetDefinition>
<sorted>false</sorted>
<value>
<fullName>Option_A</fullName>
<default>false</default>
<label>Option A</label>
</value>
</valueSetDefinition>
</valueSet>| Forbidden Attribute | Why | What Happens |
|---|---|---|
| Master-Detail is ALWAYS required by design | Deployment error |
| Master-Detail ALWAYS cascades deletes | Deployment error |
| Only supported on Lookup fields | Deployment error |
| Attribute | Master-Detail | Lookup |
|---|---|---|
| ❌ FORBIDDEN | ✅ Optional |
| ❌ FORBIDDEN (always CASCADE) | ✅ Required ( |
| ❌ FORBIDDEN | ✅ Optional |
| ✅ Required (0 or 1) | ❌ Not applicable |
| ✅ Optional | ❌ Not applicable |
| ✅ Optional | ❌ Not applicable |
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Account__c</fullName>
<label>Account</label>
<type>MasterDetail</type>
<referenceTo>Account</referenceTo>
<relationshipName>Contacts</relationshipName>
<relationshipOrder>0</relationshipOrder>
<required>true</required> <!-- WRONG: Remove this -->
<deleteConstraint>Cascade</deleteConstraint> <!-- WRONG: Remove this -->
<lookupFilter> <!-- WRONG: Remove this entire block -->
<active>true</active>
<filterItems>
<field>Account.Type</field>
<operation>equals</operation>
<value>Customer</value>
</filterItems>
</lookupFilter>
</CustomField>Master-Detail Relationship Fields Cannot be Optional or RequiredCan not specify 'deleteConstraint' for a CustomField of type MasterDetailLookup filters are only supported on Lookup Relationship Fields<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Account__c</fullName>
<label>Account</label>
<description>Links this record to its parent Account</description>
<type>MasterDetail</type>
<referenceTo>Account</referenceTo>
<relationshipLabel>Child Records</relationshipLabel>
<relationshipName>ChildRecords</relationshipName>
<relationshipOrder>0</relationshipOrder>
<reparentableMasterDetail>false</reparentableMasterDetail>
<writeRequiresMasterRead>false</writeRequiresMasterRead>
<!-- NO required, deleteConstraint, or lookupFilter -->
</CustomField><CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Related_Account__c</fullName>
<label>Related Account</label>
<description>Optional link to a related Account</description>
<type>Lookup</type>
<referenceTo>Account</referenceTo>
<relationshipLabel>Related Records</relationshipLabel>
<relationshipName>RelatedRecords</relationshipName>
<required>false</required>
<deleteConstraint>SetNull</deleteConstraint>
<lookupFilter>
<active>true</active>
<filterItems>
<field>Account.Type</field>
<operation>equals</operation>
<value>Customer</value>
</filterItems>
<isOptional>false</isOptional>
</lookupFilter>
</CustomField>01Travel_Bookings| Element | Requirement | Format |
|---|---|---|
| Required | Always |
| Required | |
| Required | |
| Conditional | Required for |
| Forbidden Attribute | Why |
|---|---|
| Summary inherits from summarized field |
| Summary inherits from summarized field |
| Not applicable to Summary fields |
| Not applicable to Summary fields |
summaryForeignKeysummarizedFieldChildObjectAPIName__c.FieldAPIName__csummaryForeignKeyChildObject__c.MasterDetailFieldOnChild__csummarizedFieldChildObject__c.FieldToSummarize__c<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Total_Amount__c</fullName>
<label>Total Amount</label>
<type>Summary</type>
<precision>18</precision> <!-- WRONG: Remove - inherited from source -->
<scale>2</scale> <!-- WRONG: Remove - inherited from source -->
<summaryOperation>sum</summaryOperation>
<summaryForeignKey>Order__c</summaryForeignKey> <!-- WRONG: Missing field name -->
<summarizedField>Amount__c</summarizedField> <!-- WRONG: Missing object name -->
</CustomField>Can not specify 'precision' for a CustomField of type SummaryMust specify the name in the CustomObject.CustomField format (e.g. Account.MyNewCustomField)<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Total_Amount__c</fullName>
<label>Total Amount</label>
<description>Sum of all line item amounts</description>
<inlineHelpText>Automatically calculated from child line items</inlineHelpText>
<type>Summary</type>
<summaryOperation>sum</summaryOperation>
<summarizedField>Order_Line_Item__c.Amount__c</summarizedField>
<summaryForeignKey>Order_Line_Item__c.Order__c</summaryForeignKey>
<!-- NO precision, scale, required, or length -->
</CustomField><CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Line_Item_Count__c</fullName>
<label>Line Item Count</label>
<description>Count of related line items</description>
<inlineHelpText>Automatically calculated from child records</inlineHelpText>
<type>Summary</type>
<summaryOperation>count</summaryOperation>
<summaryForeignKey>Order_Line_Item__c.Order__c</summaryForeignKey>
<!-- NO summarizedField needed for COUNT -->
<!-- NO precision, scale, required, or length -->
</CustomField><CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Earliest_Due_Date__c</fullName>
<label>Earliest Due Date</label>
<description>Earliest due date among all line items</description>
<inlineHelpText>Shows the soonest deadline</inlineHelpText>
<type>Summary</type>
<summaryOperation>min</summaryOperation>
<summarizedField>Order_Line_Item__c.Due_Date__c</summarizedField>
<summaryForeignKey>Order_Line_Item__c.Order__c</summaryForeignKey>
</CustomField><CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Highest_Price__c</fullName>
<label>Highest Price</label>
<description>Maximum unit price among all line items</description>
<inlineHelpText>Shows the most expensive item</inlineHelpText>
<type>Summary</type>
<summaryOperation>max</summaryOperation>
<summarizedField>Order_Line_Item__c.Unit_Price__c</summarizedField>
<summaryForeignKey>Order_Line_Item__c.Order__c</summaryForeignKey>
</CustomField>| Operation | summarizedField Required? | Use Case |
|---|---|---|
| NO | Count number of child records |
| YES | Add up numeric values |
| YES | Find smallest value |
| YES | Find largest value |
<formula><type>CheckboxCurrencyDateDateTimeNumberPercentText<formula><![CDATA[ ... ]]>&<>]]><![CDATA[Text_Field__c & "]]]]><![CDATA[>"]]>returnType<type>NumberCurrencyPercent<formulaTreatBlanksAs>BlankAsZero</formulaTreatBlanksAs>TextDateDateTime<formulaTreatBlanksAs>BlankAsBlank</formulaTreatBlanksAs><CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Calculated_Value__c</fullName>
<type>Formula</type> <!-- WRONG: Formula is not a valid type -->
<returnType>Number</returnType> <!-- WRONG: returnType does not exist in Metadata API -->
<formula>Field1__c + Field2__c</formula> <!-- WRONG: Missing CDATA wrapper -->
</CustomField><CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Calculated_Value__c</fullName>
<label>Calculated Value</label>
<description>Sum of Field1 and Field2</description>
<type>Number</type> <!-- Result type, not "Formula" -->
<precision>18</precision>
<scale>2</scale>
<formula><![CDATA[Field1__c + Field2__c]]></formula>
<formulaTreatBlanksAs>BlankAsZero</formulaTreatBlanksAs>
</CustomField>| Function | Rule |
|---|---|
| MUST NOT be used with Text fields. If the field is already Text, remove the |
| Last parameter is always the default value. Total parameter count MUST be even (value-result pairs + default). |
| MUST only be used with Text fields. If a Number is passed as parameter, remove the |
| MUST only be used with Date fields. If a DateTime field is used, convert it to Date first (e.g., |
| MUST only be used with Date fields. If a DateTime field is used, convert it to Date first (e.g., |
| MUST only be used with DateTime fields. If a Date field is used, remove the |
| MUST be used when checking equality of a Picklist field. NEVER use |
| Use |
| Error Message | Cause | Fix |
|---|---|---|
| XML comments placed before the root | Remove XML comments ( |
| Referenced field does not exist or has not been deployed yet | Verify the referenced field exists and is deployed before this field |
| Field fullName already exists on the object | Use a unique business-driven name |
| More than 2 Master-Detail or 15 Lookup fields on the object | Use Lookup for 3rd+ Master-Detail; review Lookup count |
| Reserved keyword error | Using | Rename to |
<fullName>__c<description><inlineHelpText><label><!-- ... --><CustomField><required><deleteConstraint><lookupFilter><relationshipOrder>01<sharingModel>ControlledByParent<deleteConstraint>SetNullRestrictCascade<relationshipName><precision><scale><summaryForeignKey>ChildObject__c.MasterDetailField__c<summarizedField>ChildObject__c.FieldName__c<summarizedField><type><formula><![CDATA[ ... ]]><returnType><formulaTreatBlanksAs>BlankAsZeroBlankAsBlankscale ≤ precisionprecision ≤ 18<length>255</length><visibleLines>OrderGroupSelect