generating-custom-object
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWhen to Use This Skill
何时使用此技能
Use this skill when you need to:
- Create new custom objects
- Generate custom object metadata XML
- Configure object sharing and security settings
- Set up object features and capabilities
- Troubleshoot deployment errors related to custom objects
当你需要以下操作时,使用此技能:
- 创建新的自定义对象
- 生成自定义对象元数据XML
- 配置对象共享和安全设置
- 设置对象功能与特性
- 排查与自定义对象相关的部署错误
Specification
规范
1. Overview and Purpose
1. 概述与目的
This document defines the mandatory constraints for generating CustomObject metadata XML ( file). The agent must verify these constraints before outputting XML to prevent Metadata API deployment errors.
.object-meta.xmlFile extension:
.object-meta.xml本文档定义了生成CustomObject元数据XML(文件)的强制约束。Agent在输出XML之前必须验证这些约束,以避免Metadata API部署错误。
.object-meta.xml文件扩展名:
.object-meta.xml2. Syntactic Essentials (Tier 1)
2. 语法要点(第一层级)
The following constraints must be true for the XML body to deploy successfully.
Note: The API Name (fullName) is NOT a tag; it is the filename (e.g., ).
Vehicle__c.object-meta.xml以下约束必须满足,XML主体才能成功部署。
注意: API名称(fullName)并非标签,而是文件名(例如:)。
Vehicle__c.object-meta.xmlRequired Elements
必填元素
| Element | Requirement | Notes |
|---|---|---|
| Required | Singular UI name |
| Required | Plural UI name |
| Required | See Sharing Model Rules below |
| Required | Always set to |
| Required | Primary record identifier (requires |
| Required | Always set to |
| 元素 | 要求 | 说明 |
|---|---|---|
| 必填 | 单数UI名称 |
| 必填 | 复数UI名称 |
| 必填 | 参见下方共享模型规则 |
| 必填 | 始终设置为 |
| 必填 | 主记录标识符(需包含 |
| 必填 | 始终设置为 |
Sharing Model Rules
共享模型规则
Default: Set to .
<sharingModel>ReadWriteException: If this object contains a Master-Detail relationship field, MUST be .
<sharingModel>ControlledByParentDecision Logic:
- IF object has NO Master-Detail field → use
ReadWrite - IF object has Master-Detail field → use
ControlledByParent - IF a Master-Detail field is being added to an existing child object → that existing object's must also be updated to
<sharingModel>ControlledByParent
❌ INCORRECT — Will cause error:
Cannot set sharingModel to ReadWrite on a CustomObject with a MasterDetail relationship fieldxml
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
<label>Order Line Item</label>
<pluralLabel>Order Line Items</pluralLabel>
<sharingModel>ReadWrite</sharingModel> <!-- WRONG: Object has a M-D field -->
<deploymentStatus>Deployed</deploymentStatus>
</CustomObject>✅ CORRECT:
xml
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
<label>Order Line Item</label>
<pluralLabel>Order Line Items</pluralLabel>
<sharingModel>ControlledByParent</sharingModel> <!-- CORRECT -->
<deploymentStatus>Deployed</deploymentStatus>
</CustomObject>默认值: 将设置为。
<sharingModel>ReadWrite例外情况: 如果此对象包含Master-Detail关系字段,必须设置为。
<sharingModel>ControlledByParent决策逻辑:
- 若对象无Master-Detail字段 → 使用
ReadWrite - 若对象有Master-Detail字段 → 使用
ControlledByParent - 若向现有子对象添加Master-Detail字段 → 该现有对象的也必须更新为
<sharingModel>ControlledByParent
❌ 错误示例 — 会导致错误:
Cannot set sharingModel to ReadWrite on a CustomObject with a MasterDetail relationship fieldxml
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
<label>Order Line Item</label>
<pluralLabel>Order Line Items</pluralLabel>
<sharingModel>ReadWrite</sharingModel> <!-- 错误:对象包含M-D字段 -->
<deploymentStatus>Deployed</deploymentStatus>
</CustomObject>✅ 正确示例:
xml
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
<label>Order Line Item</label>
<pluralLabel>Order Line Items</pluralLabel>
<sharingModel>ControlledByParent</sharingModel> <!-- 正确 -->
<deploymentStatus>Deployed</deploymentStatus>
</CustomObject>3. Smart Defaults & Decision Logic (Tier 2)
3. 智能默认值与决策逻辑(第二层级)
The agent must choose which features to enable based on the object's intended use case.
Agent必须根据对象的预期用例选择启用哪些功能。
A. The Name Field Decision
A. 名称字段决策
| Type | When to Use | Additional Requirements |
|---|---|---|
| Text | Default for human-named entities (Projects, Locations, Teams) | None |
| AutoNumber | Use for transactions, logs, or IDs (Invoices, Requests, Tickets) | Must include |
Text Name Field Example:
xml
<nameField>
<label>Project Name</label>
<type>Text</type>
</nameField>AutoNumber Name Field Example:
xml
<nameField>
<label>Invoice Number</label>
<type>AutoNumber</type>
<displayFormat>INV-{0000}</displayFormat>
<startingNumber>1</startingNumber>
</nameField>| 类型 | 使用场景 | 额外要求 |
|---|---|---|
| Text | 人类命名实体的默认类型(项目、地点、团队) | 无 |
| AutoNumber | 用于交易、日志或ID(发票、请求、工单) | 必须包含 |
Text类型名称字段示例:
xml
<nameField>
<label>Project Name</label>
<type>Text</type>
</nameField>AutoNumber类型名称字段示例:
xml
<nameField>
<label>Invoice Number</label>
<type>AutoNumber</type>
<displayFormat>INV-{0000}</displayFormat>
<startingNumber>1</startingNumber>
</nameField>B. Object Description
B. 对象描述
<description>If the intent is vague, generate a summary:
"Object used to track and manage [Intent] within the organization."
<description>如果用途不明确,生成如下摘要:
"用于在组织内跟踪和管理[用途]的对象。"
C. Junction Object Naming
C. 关联对象命名
If the object is a many-to-many link between two parents, name the object by combining the two parent entities to ensure the schema remains intuitive.
Examples:
- (links Position and Candidate)
Position_Candidate__c - (links Job and Application)
Job_Application__c
如果对象是两个父对象之间的多对多链接,需通过组合两个父实体的名称来命名对象,以确保架构直观易懂。
示例:
- (关联Position和Candidate)
Position_Candidate__c - (关联Job和Application)
Job_Application__c
D. Feature Enablement (Clean XML)
D. 功能启用(简洁XML)
To maintain "Clean XML," only include optional tags when deviating from the Salesforce platform default of .
falseScenario A: User-Facing Objects (Apps, Trackers, Business Entities)
- Trigger: The object is intended for direct user interaction
- Action: Set ,
<enableSearch>,<enableReports>, and<enableActivities>to<enableHistory>true
Scenario B: System-Facing Objects (Junctions, Background Logs)
- Trigger: The object exists for technical associations or background data
- Action: Omit these tags to keep the UI clean and the XML lean
为保持“简洁XML”,仅在偏离Salesforce平台默认值时才包含可选标签。
false场景A:面向用户的对象(应用、跟踪器、业务实体)
- 触发条件:对象用于直接用户交互
- 操作:将、
<enableSearch>、<enableReports>和<enableActivities>设置为<enableHistory>true
场景B:面向系统的对象(关联对象、后台日志)
- 触发条件:对象用于技术关联或后台数据存储
- 操作:省略这些标签,以保持UI简洁和XML精简
4. Critical Constraints & Common Failures
4. 关键约束与常见错误
Reserved Words
保留字
Never use reserved words as API names for Custom Objects or Custom Fields:
| Category | Reserved Words (Do Not Use as API Names) |
|---|---|
| SOQL/SQL | |
| System | |
| Temporal | |
切勿将保留字用作Custom Object或自定义字段的API名称:
| 类别 | 保留字(请勿用作API名称) |
|---|---|
| SOQL/SQL | |
| 系统 | |
| 时间相关 | |
Relationship Cap
关系上限
Do not create more than 2 Master-Detail relationships for a single object. If a third relationship is required, use a Lookup instead.
单个对象最多创建2个Master-Detail关系。若需要第三个关系,请改用Lookup关系。
XML Root Element
XML根元素
Do NOT include the tag at the root of the file. The API name is derived from the filename.
<fullName>.object-meta.xml❌ INCORRECT:
xml
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Vehicle__c</fullName> <!-- WRONG: Remove this -->
<label>Vehicle</label>
</CustomObject>✅ CORRECT:
xml
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
<label>Vehicle</label>
<!-- fullName comes from filename: Vehicle__c.object-meta.xml -->
</CustomObject>请勿在文件的根元素中包含标签。API名称由文件名派生而来。
.object-meta.xml<fullName>❌ 错误示例:
xml
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Vehicle__c</fullName> <!-- 错误:移除此项 -->
<label>Vehicle</label>
</CustomObject>✅ 正确示例:
xml
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
<label>Vehicle</label>
<!-- fullName来自文件名:Vehicle__c.object-meta.xml -->
</CustomObject>Validation Rule Naming Convention
验证规则命名规范
Validation rule names follow different conventions than custom fields.
Rules:
- Must contain only alphanumeric characters and underscores
- Must begin with a letter
- Cannot end with an underscore
- Cannot contain two consecutive underscores
- Must NOT end with (unlike custom fields)
__c
❌ INCORRECT:
xml
<validationRules>
<fullName>Require_Start_Date__c</fullName> <!-- WRONG: Has __c suffix -->
<active>true</active>
<errorMessage>Start Date is required.</errorMessage>
<formula>ISBLANK(Start_Date__c)</formula>
</validationRules>Error:
The validation name can only contain alphanumeric characters, must begin with a letter, cannot end with an underscore...✅ CORRECT:
xml
<validationRules>
<fullName>Require_Start_Date</fullName> <!-- CORRECT: No __c suffix -->
<active>true</active>
<errorMessage>Start Date is required.</errorMessage>
<formula>ISBLANK(Start_Date__c)</formula>
</validationRules>Naming Pattern Reference:
| Metadata Type | Naming Pattern | Example |
|---|---|---|
| Custom Fields | Ends with | |
| Validation Rules | No suffix | |
| Custom Objects | Ends with | |
验证规则的命名规范与自定义字段不同。
规则:
- 只能包含字母数字字符和下划线
- 必须以字母开头
- 不能以下划线结尾
- 不能包含两个连续的下划线
- 不能以结尾(与自定义字段不同)
__c
❌ 错误示例:
xml
<validationRules>
<fullName>Require_Start_Date__c</fullName> <!-- 错误:包含__c后缀 -->
<active>true</active>
<errorMessage>Start Date is required.</errorMessage>
<formula>ISBLANK(Start_Date__c)</formula>
</validationRules>错误提示:
The validation name can only contain alphanumeric characters, must begin with a letter, cannot end with an underscore...✅ 正确示例:
xml
<validationRules>
<fullName>Require_Start_Date</fullName> <!-- 正确:无__c后缀 -->
<active>true</active>
<errorMessage>Start Date is required.</errorMessage>
<formula>ISBLANK(Start_Date__c)</formula>
</validationRules>命名模式参考:
| 元数据类型 | 命名模式 | 示例 |
|---|---|---|
| 自定义字段 | 以 | |
| 验证规则 | 无后缀 | |
| Custom Object | 以 | |
5. Verification Checklist
5. 验证清单
Before generating the Custom Object XML, verify:
在生成Custom Object XML之前,请验证以下内容:
Syntactic Checks
语法检查
- Are both and
<label>present?<pluralLabel> - Is set to
<deploymentStatus>?Deployed - Is set to
<visibility>?Public - Does include both
<nameField>and<label>?<type> - If is
<type>, areAutoNumberand<displayFormat>included?<startingNumber>
- 是否同时存在和
<label>?<pluralLabel> - 是否设置为
<deploymentStatus>?Deployed - 是否设置为
<visibility>?Public - 是否包含
<nameField>和<label>?<type> - 若为
<type>,是否包含AutoNumber和<displayFormat>?<startingNumber>
Sharing Model Check (Critical)
共享模型检查(关键)
- Does this object have a Master-Detail relationship field?
- If YES → MUST be
<sharingModel>ControlledByParent - If NO → should be
<sharingModel>ReadWrite
- If YES →
- 此对象是否包含Master-Detail关系字段?
- 若是 → 必须为
<sharingModel>ControlledByParent - 若否 → 应设为
<sharingModel>ReadWrite
- 若是 →
Constraint Checks
约束检查
- Is the API name free of reserved words?
- Are there 2 or fewer Master-Detail relationships?
- Is absent from the XML root?
<fullName>
- API名称是否不含保留字?
- Master-Detail关系是否不超过2个?
- XML根元素中是否没有?
<fullName>
Validation Rule Checks (if applicable)
验证规则检查(若适用)
- Do validation rule names NOT end with ?
__c - Do validation rule names follow alphanumeric + underscore pattern?
- 验证规则名称是否不以结尾?
__c - 验证规则名称是否符合字母数字+下划线的模式?
Architectural Checks
架构检查
- Is present with a meaningful summary?
<description> - Are and
<enableSearch>set to<enableReports>if user-facing?true - Does the filename match the intended API name?
- 是否存在且包含有意义的摘要?
<description> - 若面向用户,和
<enableSearch>是否设置为<enableReports>?true - 文件名是否与预期API名称匹配?