Create Custom Field
CRITICAL - Output Type
This skill creates
CustomFieldmetadata ONLY.NEVER create:
- •
CustomObjectTranslationfiles (translations)- •
objectTranslationsfiles- •Any file with Hebrew labels inside XML
ALWAYS create:
- •
CustomFieldXML files inforce-app/main/default/objects/<Object>/fields/- •Labels must be in ENGLISH ONLY
Prefix Rules for FIELDS (CRITICAL)
NOTE: This skill is for creating FIELDS only, not Objects. For creating Objects, use the
create-objectskill.
Before creating any field, determine the target object type:
| Target Object Type | Field API Name Format | Example |
|---|---|---|
| Field on Standard Object (Account, Contact, Opportunity, etc.) | <PREFIX>_<FieldName>__c | VST_Status__c |
Field on Custom Object (object name ends with __c) | <FieldName>__c (NO prefix for the field) | Status__c |
IMPORTANT: This rule applies to FIELD names only. Custom Objects themselves ALWAYS require the prefix (see create-object skill).
The PREFIX is defined in
copilot-instructions.md
Default Field Type (CRITICAL - DO NOT ASK USER)
When the user does not specify a field type, apply these defaults AUTOMATICALLY without asking:
| Missing Information | Default Value | Notes |
|---|---|---|
| Field Type | Text | Always default to Text |
| Text Length | 255 | Standard max for Text |
| Number Precision | 16 | Total digits including decimals |
| Number Scale | 0 | No decimal places by default |
Rules:
- •NEVER ask the user for field type if not specified - use Text(255)
- •NEVER ask the user for length/precision - use defaults above
- •NEVER ask the user about decimal places - use scale=0
- •Only ask if the target object is truly ambiguous (e.g., "Visit" could be multiple objects)
MANDATORY Field Properties by Type (CRITICAL)
ALWAYS include the required properties for each field type. Missing properties will cause deployment errors.
| Field Type | Required Properties | Example |
|---|---|---|
| Text | <length> (1-255) | <length>255</length> |
| TextArea | <length> (max 131072) | <length>32768</length> |
| LongTextArea | <length>, <visibleLines> | <length>32768</length><visibleLines>5</visibleLines> |
| Html (Rich Text) | <length>, <visibleLines> | <length>32768</length><visibleLines>10</visibleLines> |
| Number | <precision>, <scale> | <precision>18</precision><scale>0</scale> |
| Currency | <precision>, <scale> | <precision>18</precision><scale>2</scale> |
| Percent | <precision>, <scale> | <precision>5</precision><scale>2</scale> |
| Checkbox | <defaultValue> | <defaultValue>false</defaultValue> |
| Date | (none required) | - |
| DateTime | (none required) | - |
| Picklist | <valueSet> | See Picklist template below |
| Lookup | <referenceTo>, <relationshipName> | See Lookup template below |
Common Errors to AVOID:
- •"length must be specified" → Always add
<length>for Text fields - •"RichTextArea is not valid" → Use
<type>Html</type>instead ofRichTextArea - •Picklist formula error → Use
ISPICKVAL(field, "value")notfield = "value"
File Location
force-app/main/default/objects/<ObjectAPIName>/fields/<FieldAPIName>.field-meta.xml
Field Metadata Template
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>{FieldAPIName}</fullName>
<label>{FieldLabel}</label>
<type>Text</type>
<length>255</length>
</CustomField>
Examples
Example 1: Field on Standard Object (Account)
Request: "Create a Status field on Account"
Result:
- •API Name:
VST_Status__c(with prefix) - •File:
force-app/main/default/objects/Account/fields/VST_Status__c.field-meta.xml
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>VST_Status__c</fullName>
<label>Status</label>
<type>Text</type>
<length>255</length>
</CustomField>
Example 2: Field on Custom Object
Request: "Create an EndDate field on VST_Visit__c"
Result:
- •API Name:
EndDate__c(NO prefix for the FIELD - because it's on a custom object) - •File:
force-app/main/default/objects/VST_Visit__c/fields/EndDate__c.field-meta.xml
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>EndDate__c</fullName>
<label>End Date</label>
<type>Date</type>
</CustomField>
Object Existence Check (CRITICAL)
Before creating a field, verify the target object exists in the project:
- •Check if the object folder exists:
force-app/main/default/objects/<ObjectAPIName>/ - •If the object does NOT exist:
- •DO NOT create the object automatically
- •DO NOT assume the user wants a new object
- •STOP and inform the user: "The object
<ObjectAPIName>was not found in the project." - •Wait for user instructions
Example response when object not found:
The object
VST_Visit__cwas not found in the project. Please create the object first or specify a different object.
Validation Checklist
Before creating a field:
- • Target object is specified (if not - ASK)
- • Target object exists in the project (if not - STOP and inform user)
- • Object type determined (standard vs custom)
- • Correct prefix rule applied
- • Label is in English (translate Hebrew if needed)
- • Label does NOT contain the prefix
- • All required properties for the field type are included (see table above)
Additional Field Templates
Checkbox Field
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>IsActive__c</fullName>
<label>Is Active</label>
<defaultValue>false</defaultValue>
<type>Checkbox</type>
</CustomField>
Number Field
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Quantity__c</fullName>
<label>Quantity</label>
<precision>18</precision>
<scale>0</scale>
<type>Number</type>
</CustomField>
Rich Text (Html) Field
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Description__c</fullName>
<label>Description</label>
<length>32768</length>
<type>Html</type>
<visibleLines>10</visibleLines>
</CustomField>
Picklist Field
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Status__c</fullName>
<label>Status</label>
<type>Picklist</type>
<valueSet>
<valueSetDefinition>
<sorted>false</sorted>
<value>
<fullName>Draft</fullName>
<default>true</default>
<label>Draft</label>
</value>
<value>
<fullName>Active</fullName>
<default>false</default>
<label>Active</label>
</value>
<value>
<fullName>Closed</fullName>
<default>false</default>
<label>Closed</label>
</value>
</valueSetDefinition>
</valueSet>
</CustomField>
Lookup Field
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Account__c</fullName>
<label>Account</label>
<type>Lookup</type>
<referenceTo>Account</referenceTo>
<relationshipName>RelatedRecords</relationshipName>
<relationshipLabel>Related Records</relationshipLabel>
</CustomField>
Formula Field (Checkbox result)
NOTE: When comparing Picklist fields in formulas, ALWAYS use ISPICKVAL() function!
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>IsReady__c</fullName>
<label>Is Ready</label>
<type>Checkbox</type>
<formula>ISPICKVAL(Status__c, "Active")</formula>
<formulaTreatBlanksAs>BlankAsZero</formulaTreatBlanksAs>
</CustomField>
WRONG (will cause error): Status__c = "Active"
CORRECT: ISPICKVAL(Status__c, "Active")