AgentSkillsCN

create-field

创建 Salesforce 自定义字段。当用户请求在任意 Salesforce 对象上创建字段、新增字段,或定义新的自定义字段时,请使用此技能。系统会根据目标对象类型,自动处理前缀规则。

SKILL.md
--- frontmatter
name: create-field
description: 'Create Salesforce custom fields. Use this skill when users request to create a field, add a field, or define a new custom field on any Salesforce object. Handles prefix rules automatically based on target object type.'

Create Custom Field

CRITICAL - Output Type

This skill creates CustomField metadata ONLY.

NEVER create:

  • CustomObjectTranslation files (translations)
  • objectTranslations files
  • Any file with Hebrew labels inside XML

ALWAYS create:

  • CustomField XML files in force-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-object skill.

Before creating any field, determine the target object type:

Target Object TypeField API Name FormatExample
Field on Standard Object (Account, Contact, Opportunity, etc.)<PREFIX>_<FieldName>__cVST_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 InformationDefault ValueNotes
Field TypeTextAlways default to Text
Text Length255Standard max for Text
Number Precision16Total digits including decimals
Number Scale0No decimal places by default

Rules:

  1. NEVER ask the user for field type if not specified - use Text(255)
  2. NEVER ask the user for length/precision - use defaults above
  3. NEVER ask the user about decimal places - use scale=0
  4. 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 TypeRequired PropertiesExample
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 of RichTextArea
  • Picklist formula error → Use ISPICKVAL(field, "value") not field = "value"

File Location

code
force-app/main/default/objects/<ObjectAPIName>/fields/<FieldAPIName>.field-meta.xml

Field Metadata Template

xml
<?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
<?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
<?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:

  1. Check if the object folder exists: force-app/main/default/objects/<ObjectAPIName>/
  2. 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__c was 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
<?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
<?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
<?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
<?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
<?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
<?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")