Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问许可证需确认审计通过

generating-custom-field生成自定义字段

Agent Skill

generating-custom-field 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

8,751

周安装

354

GitHub Stars

212

下载量

2,747
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:generating-custom-field(生成自定义字段)
来源仓库:https://github.com/forcedotcom/afv-library
仓库路径:skills/generating-custom-field
安装命令:
npx skills add https://github.com/forcedotcom/afv-library --skill generating-custom-field
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/forcedotcom/afv-library --skill generating-custom-field

简介

生成 Salesforce 自定义字段配置 XML,支持复杂值集与主从关系。

  • 适用于 CRM 系统扩展与数据模型定制开发。
  • 严格遵循字段类型、长度与关联规则限制。
  • 输出前需人工审核以确保符合组织安全策略。
  • generating-custom-field 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

When to Use This Skill

Use this skill when you need to:

  • Create custom fields on any object
  • Generate field metadata for any field type
  • Set up relationship fields (Lookup or Master-Detail)
  • Create formula or roll-up summary fields
  • Troubleshoot deployment errors related to custom fields

Salesforce Custom Field Generator and Validator

Overview

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.

Specification

1. Purpose

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.

Critical Focus Areas:

  • Roll-up Summary field format errors
  • Master-Detail field attribute restrictions
  • Lookup Filter restrictions

2. Universal Mandatory Attributes

Every generated field must include these tags:

AttributeRequirementNotes
<fullName>RequiredDerive from <label>: capitalize each word, replace spaces with _, append __c. Must start with a letter. E.g., label Total Contract ValueTotal_Contract_Value__c
<label>RequiredThe UI name (Title Case)
<description>MandatoryState the business "why" behind the field
<inlineHelpText>MandatoryProvide 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")

External ID Configuration

Trigger: If the user mentions "integration," "importing data," "external system ID," or "unique key from [System Name]," set <externalId>true</externalId>.

Applicable Types: Text, Number, Email


3. Technical Interplay: Precision, Scale, and Length

To ensure deployment success, follow these mathematical constraints:

Precision vs. Scale Rules

  • precision is the total digits; scale is the decimal digits
  • Rule: precision ≤ 18 AND scale ≤ precision
  • Calculation: Digits to the left of decimal = precision - scale

The "Fixed 255" Rule

For standard TextArea types, the Metadata API requires <length>255</length>, even though it isn't configurable in the UI.

Visible Lines

Mandatory for Long/Rich text and Multi-select picklists to control UI height.


4. Field Data Types

4.1 Simple Attribute Types

Type<type> ValueRequired Attributes
Auto NumberAutoNumberdisplayFormat (must include {0}), startingNumber
CheckboxCheckboxDefault defaultValue to false
DateDateNo precision/length required
Date/TimeDateTimeNo precision/length required
EmailEmailBuilt-in format validation
Lookup RelationshipLookupreferenceTo, relationshipName, deleteConstraint
Master-Detail RelationshipMasterDetailreferenceTo, relationshipName, relationshipOrder
NumberNumberprecision, scale
CurrencyCurrencyDefault precision: 18, scale: 2
PercentPercentDefault precision: 5, scale: 2
PhonePhoneStandardizes phone number formatting
PicklistPicklistvalueSet with valueSetDefinition and restricted
TextTextlength (Max 255)
Text AreaTextArea<length>255</length>
Text (Long)LongTextArealength, visibleLines (default 3)
Text (Rich)Htmllength, visibleLines (default 25)
TimeTimeStores time only (no date)
URLUrlValidates for protocol and format

4.2 Computed & Multi-Value Types

Type<type> ValueRequired Attributes
FormulaResult type (e.g., Number)formula, formulaTreatBlanksAs
Roll-Up SummarySummarySee Section 6 for complete requirements
Multi-Select PicklistMultiselectPicklistvalueSet, visibleLines (default 4)

4.3 Specialized Types

Type<type> ValueRequired Attributes
GeolocationLocationscale, displayLocationInDecimal

Picklist restricted Rule

The <restricted> boolean inside <valueSet> controls whether only admin-defined values are allowed.

  • IF user does not specify → default to <restricted>true</restricted> (restricted, avoids performance issues with large picklist value sets)
  • IF user explicitly says the picklist should allow custom/new values, or mentions "unrestricted" or "open" → set <restricted>false</restricted>
  • Restricted picklists are limited to 1,000 total values (active + inactive)
<valueSet>
  <restricted>true</restricted>
  <valueSetDefinition>
    <sorted>false</sorted>
    <value>
      <fullName>Option_A</fullName>
      <default>false</default>
      <label>Option A</label>
    </value>
  </valueSetDefinition>
</valueSet>

5. Master-Detail Relationship Rules ⭐ CRITICAL

Master-Detail fields have strict attribute restrictions that differ from Lookup fields. Violating these rules causes deployment failures.

Forbidden Attributes on Master-Detail Fields

NEVER include these attributes on Master-Detail fields:

Forbidden AttributeWhyWhat Happens
<required>Master-Detail is ALWAYS required by designDeployment error
<deleteConstraint>Master-Detail ALWAYS cascades deletesDeployment error
<lookupFilter>Only supported on Lookup fieldsDeployment error

Master-Detail vs Lookup Comparison

AttributeMaster-DetailLookup
<required>❌ FORBIDDEN✅ Optional
<deleteConstraint>❌ FORBIDDEN (always CASCADE)✅ Required (SetNull, Restrict, Cascade)
<lookupFilter>❌ FORBIDDEN✅ Optional
<relationshipOrder>✅ Required (0 or 1)❌ Not applicable
<reparentableMasterDetail>✅ Optional❌ Not applicable
<writeRequiresMasterRead>✅ Optional❌ Not applicable

❌ INCORRECT — Master-Detail with forbidden attributes:

<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>

Errors:

  • Master-Detail Relationship Fields Cannot be Optional or Required
  • Can not specify 'deleteConstraint' for a CustomField of type MasterDetail
  • Lookup filters are only supported on Lookup Relationship Fields

✅ CORRECT — Master-Detail field:

<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>

✅ CORRECT — Lookup field (with optional attributes):

<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>

Additional Master-Detail Rules

  • Relationship Order: First Master-Detail on object = 0, second = 1
  • Relationship Name: Must be a plural PascalCase string (e.g., Travel_Bookings)
  • Junction Objects: Use two Master-Detail fields for standard many-to-many (enables Roll-ups)
  • Limit: Maximum 2 Master-Detail relationships per object. Use Lookup for additional relationships.

6. Roll-Up Summary Field Rules ⭐ CRITICAL

Roll-up Summary fields have the highest deployment failure rate. Follow these rules exactly.

Required Elements for Roll-Up Summary

ElementRequirementFormat
<type>RequiredAlways Summary
<summaryOperation>Requiredcount, sum, min, or max
<summaryForeignKey>RequiredChildObject__c.MasterDetailField__c
<summarizedField>ConditionalRequired for sum, min, max. NOT for count

Forbidden Elements on Roll-Up Summary

NEVER include these attributes on Roll-Up Summary fields:

Forbidden AttributeWhy
<precision>Summary inherits from summarized field
<scale>Summary inherits from summarized field
<required>Not applicable to Summary fields
<length>Not applicable to Summary fields

Format Rules for summaryForeignKey and summarizedField

CRITICAL: Both summaryForeignKey and summarizedField MUST use the fully qualified format:

ChildObjectAPIName__c.FieldAPIName__c

Decision Logic:

  • summaryForeignKey = ChildObject__c.MasterDetailFieldOnChild__c
  • summarizedField = ChildObject__c.FieldToSummarize__c

❌ INCORRECT — Roll-Up Summary with common errors:

<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>

Errors:

  • Can not specify 'precision' for a CustomField of type Summary
  • Must specify the name in the CustomObject.CustomField format (e.g. Account.MyNewCustomField)

✅ CORRECT — Roll-Up Summary (SUM operation):

<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>

✅ CORRECT — Roll-Up Summary (COUNT operation):

<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>

✅ CORRECT — Roll-Up Summary (MIN operation):

<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>

✅ CORRECT — Roll-Up Summary (MAX operation):

<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>

Roll-Up Summary Quick Reference

OperationsummarizedField Required?Use Case
countNOCount number of child records
sumYESAdd up numeric values
minYESFind smallest value
maxYESFind largest value

Roll-Up Summary Prerequisites

  • Roll-Up Summary fields can ONLY be created on the parent object in a Master-Detail relationship
  • The child object MUST have a Master-Detail field pointing to this parent
  • The summarized field must exist on the child object

7. Formula Field Rules

Formula Result Types

A Formula is not a type itself. The <formula> tag is added to a field whose <type> is set to the result data type:

  • Checkbox, Currency, Date, DateTime, Number, Percent, Text

Formula XML Generation Rules

  • 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.
  • If the formula text itself contains the literal sequence ]]>, escape it by breaking the CDATA block: e.g., <![CDATA[Text_Field__c & "]]]]><![CDATA[>"]]>
  • 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.

formulaTreatBlanksAs Rule

Decision Logic:

  • IF formula result type = Number, Currency, or Percent → set <formulaTreatBlanksAs>BlankAsZero</formulaTreatBlanksAs>
  • IF formula result type = Text, Date, or DateTime → set <formulaTreatBlanksAs>BlankAsBlank</formulaTreatBlanksAs>

❌ INCORRECT — Using Formula as type:

<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>

✅ CORRECT — Formula field:

<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>

Formula Field Dependencies

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.

Specific Function Guidelines

FunctionRule
TEXT()MUST NOT be used with Text fields. If the field is already Text, remove the TEXT() wrapper.
CASE()Last parameter is always the default value. Total parameter count MUST be even (value-result pairs + default).
VALUE()MUST only be used with Text fields. If a Number is passed as parameter, remove the VALUE() wrapper.
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))).
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))).
DATEVALUE()MUST only be used with DateTime fields. If a Date field is used, remove the DATEVALUE() wrapper.
ISPICKVAL()MUST be used when checking equality of a Picklist field. NEVER use == with Picklist fields.
ISCHANGED()Use ISCHANGED() to check if a field value has changed. Do not manually compare with PRIORVALUE().

8. Common Deployment Errors

Error MessageCauseFix
ConversionError: Invalid XML tags or unable to find matching parent xml file for CustomFieldXML comments placed before the root <CustomField> elementRemove XML comments (<!--... -->) that appear before <CustomField> in the .field-meta.xml file
Field [FieldName] does not exist. Check spelling.Referenced field does not exist or has not been deployed yetVerify the referenced field exists and is deployed before this field
DUPLICATE_DEVELOPER_NAMEField fullName already exists on the objectUse a unique business-driven name
MAX_RELATIONSHIPS_EXCEEDEDMore than 2 Master-Detail or 15 Lookup fields on the objectUse Lookup for 3rd+ Master-Detail; review Lookup count
Reserved keyword errorUsing Order__c, Group__c, etc.Rename to Status_Order__c, etc.

9. Verification Checklist

Before generating CustomField XML, verify:

Universal Checks

  • Does <fullName> use valid format and end in __c?
  • Are <description> and <inlineHelpText> both populated and meaningful?
  • Is <label> in Title Case?
  • Are there no XML comments (<!--... -->) before the root <CustomField> element? (Comments before the root element break SDR's parser)

Master-Detail Field Checks ⭐ CRITICAL

  • Is <required> attribute ABSENT? (Master-Detail is always required)
  • Is <deleteConstraint> attribute ABSENT? (Master-Detail always cascades)
  • Is <lookupFilter> block ABSENT? (Only for Lookup fields)
  • Is <relationshipOrder> set to 0 or 1?
  • Is parent object's <sharingModel> set to ControlledByParent?

Lookup Field Checks

  • Is <deleteConstraint> set to SetNull, Restrict, or Cascade?
  • Is <relationshipName> in plural PascalCase?

Roll-Up Summary Field Checks ⭐ CRITICAL

  • Is <precision> attribute ABSENT?
  • Is <scale> attribute ABSENT?
  • Is <summaryForeignKey> in format ChildObject__c.MasterDetailField__c?
  • For SUM/MIN/MAX: Is <summarizedField> in format ChildObject__c.FieldName__c?
  • For COUNT: Is <summarizedField> ABSENT?
  • Does the child object have a Master-Detail field to this parent?

Formula Field Checks

  • Is <type> set to result type (NOT "Formula")?
  • Is <formula> content wrapped in <![CDATA[...]]>?
  • Is <returnType> attribute ABSENT? (does not exist in Metadata API)
  • Is <formulaTreatBlanksAs> set to BlankAsZero for numeric results or BlankAsBlank for text/date results?
  • Do all referenced fields exist and deploy before this field?

Numeric Field Checks

  • Is scale ≤ precision?
  • Is precision ≤ 18?

Text Area Checks

  • For TextArea: Is <length>255</length> explicitly included?
  • For LongTextArea/Html: Is <visibleLines> set?

Relationship Limit Checks

  • Are there 2 or fewer Master-Detail relationships on the object?
  • Are there 15 or fewer Lookup relationships on the object?

Naming Checks

  • Is the API name free of reserved words (Order, Group, Select, etc.)?
  • Is the API name unique on this object?

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

34.73%
按下载量换算954

Claude

34.66%
按下载量换算952

Cursor

18.39%
按下载量换算505

Gemini CLI

9.75%
按下载量换算268

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills