platform-custom-report-type-generate
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSpecification
规范
Salesforce Custom Report Type Metadata Knowledge
Salesforce Custom Report Type元数据知识
Overview
概述
Custom Report Types (CRTs) define the data framework for Salesforce reports. They specify a primary object, up to 3 related objects, the relationship (join) between them, and which fields are available in the report builder.
Custom Report Types(CRTs)为Salesforce报表定义了数据框架。它们指定一个主对象、最多3个相关对象、对象间的关系(连接),以及报表构建器中可用的字段。
Purpose
用途
- Enable reporting across custom objects and custom relationships not covered by standard report types
- Curate a focused set of fields for report builders (including fields reached via lookup)
- Control inner/outer join behavior to include or exclude primary records without related records
- 支持标准报表类型未覆盖的自定义对象和自定义关系的报表制作
- 为报表构建器整理一组聚焦的字段(包括通过查找关系获取的字段)
- 控制内/外连接行为,以包含或排除无相关记录的主对象记录
Configuration
配置
File extension: . The file basename is the report type's developer name (e.g. ). Each CRT is a single file, not nested under an object folder.
.reportType-meta.xmlAccountsWithProjects.reportType-meta.xml文件扩展名: 。文件基名为报表类型的开发者名称(例如)。每个CRT对应一个单独的文件,无需嵌套在对象文件夹下。
.reportType-meta.xmlAccountsWithProjects.reportType-meta.xmlKey Elements
关键元素
Top-level children:
<ReportType>| Element | Required | Notes |
|---|---|---|
| Yes | API identifier; must match the file name. Letters, numbers, underscores; must begin with a letter; no spaces; no trailing underscore; no consecutive underscores |
| Yes | Human-friendly name shown in the report type picker |
| Recommended | State the business "why" — who uses this and what they learn |
| Yes | API name of the primary object (e.g. |
| Recommended | Report builder category — see |
| Yes | |
| Conditional | Adds a related object and its join behavior. Nest further |
| Recommended | Groups of columns available to the report type. Though not strictly required, a report without columns isn't useful |
<sections>| Element | Required | Notes |
|---|---|---|
| Yes | Section heading shown in the report builder |
| Conditional | One per field exposed in the section |
<columns>| Element | Required | Notes |
|---|---|---|
| Yes | Field API name (or dotted lookup-traversal path) |
| Yes | The object the field belongs to — base object name or dotted relationship path |
| Yes | |
| No | Custom column label shown in the report builder, overriding the field's default label |
顶级子元素:
<ReportType>| 元素 | 是否必填 | 说明 |
|---|---|---|
| 是 | API标识符;必须与文件名匹配。可包含字母、数字、下划线;必须以字母开头;无空格;无末尾下划线;无连续下划线 |
| 是 | 在报表类型选择器中显示的友好名称 |
| 推荐 | 说明业务用途——谁使用它以及能获取什么信息 |
| 是 | 主对象的API名称(例如 |
| 推荐 | 报表构建器类别——请查看 |
| 是 | |
| 可选 | 添加相关对象及其连接行为。可嵌套更多 |
| 推荐 | 报表类型可用的列组。虽然并非严格必填,但没有列的报表毫无用处 |
<sections>| 元素 | 是否必填 | 说明 |
|---|---|---|
| 是 | 在报表构建器中显示的节标题 |
| 可选 | 节中暴露的每个字段对应一个该元素 |
<columns>| 元素 | 是否必填 | 说明 |
|---|---|---|
| 是 | 字段API名称(或带点的查找遍历路径) |
| 是 | 字段所属的对象——主对象名称或带点的关系路径 |
| 是 | |
| 否 | 在报表构建器中显示的自定义列标签,用于覆盖字段的默认标签 |
Critical Rules (Read First)
重要规则(请先阅读)
Rule 1: If <fullName>
Is Present, It Must Match the File Name
<fullName>规则1:如果包含<fullName>
,必须与文件名匹配
<fullName>In source format, is inherited from and derived from the file name, so the element is technically optional. The repo convention is to include it. If you include , its value must equal the file name (everything before ) exactly — same characters, same casing, same underscores.
fullNameMetadata<fullName><fullName>.reportType-meta.xmlWrong — file name and differ:
<fullName>- File:
account_projects.reportType-meta.xml - (Mismatch: file uses
<fullName>AccountProjects</fullName>, fullName usesaccount_projects)AccountProjects
Right — file name and are identical:
<fullName>- File:
AccountProjects.reportType-meta.xml <fullName>AccountProjects</fullName>
在源格式中,继承自并由文件名派生,因此元素在技术上是可选的。本仓库的惯例是包含该元素。如果您包含,其值必须与文件名(之前的部分)完全一致——字符、大小写、下划线都必须相同。
fullNameMetadata<fullName><fullName>.reportType-meta.xml错误示例——文件名与不一致:
<fullName>- 文件:
account_projects.reportType-meta.xml - (不匹配:文件使用
<fullName>AccountProjects</fullName>,fullName使用account_projects)AccountProjects
正确示例——文件名与完全一致:
<fullName>- 文件:
AccountProjects.reportType-meta.xml <fullName>AccountProjects</fullName>
Rule 2: Join Semantics — outerJoin
Controls Inclusion
outerJoin规则2:连接语义——outerJoin
控制记录包含逻辑
outerJoinEach block has an element that determines which primary records appear in the report:
<join><outerJoin> | Behavior | Report Builder Label |
|---|---|---|
| Inner join — only primary records that HAVE at least one related record | "Each 'A' record must have at least one related 'B' record" |
| Outer join — all primary records, with or without related records | "'A' records may or may not have related 'B' records" |
Default when unspecified: Use (outer join) when the user wants to see all primary records regardless of children. Use when the report only makes sense if children exist.
truefalse每个块都有一个元素,用于确定哪些主对象记录会出现在报表中:
<join><outerJoin> | 行为 | 报表构建器标签 |
|---|---|---|
| 内连接——仅包含至少有一条相关记录的主对象记录 | "每个'A'记录必须至少有一条相关的'B'记录" |
| 外连接——包含所有主对象记录,无论是否有相关记录 | "'A'记录可能有也可能没有相关的'B'记录" |
未指定时的默认值:当用户希望查看所有主对象记录而不管是否有子记录时,使用(外连接)。当只有存在子记录时报表才有意义时,使用。
truefalseRule 3: Each Object Needs Its Own <sections>
Block
<sections>规则3:每个对象都需要独立的<sections>
块
<sections>Every object in the CRT (primary + each joined object) must have a corresponding block that lists the fields exposed for reporting. Without a section for an object, none of its fields appear in the report builder.
<sections>- on each section is the section heading in the report builder
<masterLabel> - entries list the fields — each with a
<columns>(API name) and<field>(object API name)<table> - For fields reached via lookup, use the relationship path in (e.g.
<field>withOwner.Nameset to the owning object)<table>
CRT中的每个对象(主对象 + 每个连接对象)都必须有对应的块,列出用于报表的暴露字段。如果某个对象没有对应的节,其所有字段都不会出现在报表构建器中。
<sections>- 每个节的是报表构建器中的节标题
<masterLabel> - 条目列出字段——每个条目包含
<columns>(API名称)和<field>(对象API名称)<table> - 对于通过查找关系获取的字段,在中使用关系路径(例如
<field>,同时Owner.Name设置为所属对象)<table>
Rule 4: Field API Names, Not Labels
规则4:使用字段API名称,而非标签
Use exact API names for fields: standard fields use their defined names (, , ), custom fields use . Custom objects must include .
NameCreatedDateOwnerIdField__c__cWrong:
<field>Account Name</field>
Right:
- with
<field>Name</field><table>Account</table>
使用字段的精确API名称:标准字段使用其定义的名称(、、),自定义字段使用。自定义对象必须包含。
NameCreatedDateOwnerIdField__c__c错误示例:
<field>Account Name</field>
正确示例:
- 搭配
<field>Name</field><table>Account</table>
Rule 5: Relationship Path for Joined Objects
规则5:连接对象的关系路径
When adding a , the element must use the child relationship name as defined on the lookup/master-detail field pointing from the child object to the parent. For custom relationships, this typically ends in .
<join><relationship>__rWrong:
- (for a custom child relationship)
<relationship>Project</relationship>
Right:
- (child relationship name)
<relationship>Projects__r</relationship> - (standard, non-custom child relationship)
<relationship>Contacts</relationship>
添加时,元素必须使用子关系名称,即从子对象指向父对象的查找/主明细字段中定义的名称。对于自定义关系,通常以结尾。
<join><relationship>__r错误示例:
- (针对自定义子关系)
<relationship>Project</relationship>
正确示例:
- (子关系名称)
<relationship>Projects__r</relationship> - (标准非自定义子关系)
<relationship>Contacts</relationship>
Rule 6: Maximum 4 Objects Total in a Join Chain
规则6:连接链中最多包含4个对象
A single CRT can join a maximum of four objects total (the base object + up to 3 additional objects via nested blocks).
<join>单个CRT最多可连接4个对象(主对象 + 最多3个通过嵌套块添加的额外对象)。
<join>Rule 7: No Inner Join After an Outer Join
规则7:外连接之后不能使用内连接
Once the join chain contains an outer join (), every subsequent nested join must also be an outer join. An inner join that follows an outer join earlier in the sequence is not allowed.
<outerJoin>true</outerJoin>Wrong:
xml
<join>
<outerJoin>true</outerJoin> <!-- outer join first -->
<relationship>Contacts</relationship>
<join>
<outerJoin>false</outerJoin> <!-- WRONG: inner join after outer -->
<relationship>Assets</relationship>
</join>
</join>Right:
xml
<join>
<outerJoin>true</outerJoin>
<relationship>Contacts</relationship>
<join>
<outerJoin>true</outerJoin> <!-- outer stays outer -->
<relationship>Assets</relationship>
</join>
</join>一旦连接链中包含外连接(),后续所有嵌套连接也必须是外连接。不允许在序列中先出现外连接后出现内连接。
<outerJoin>true</outerJoin>错误示例:
xml
<join>
<outerJoin>true</outerJoin> <!-- 先使用外连接 -->
<relationship>Contacts</relationship>
<join>
<outerJoin>false</outerJoin> <!-- 错误:外连接后使用内连接 -->
<relationship>Assets</relationship>
</join>
</join>正确示例:
xml
<join>
<outerJoin>true</outerJoin>
<relationship>Contacts</relationship>
<join>
<outerJoin>true</outerJoin> <!-- 外连接保持外连接 -->
<relationship>Assets</relationship>
</join>
</join>Rule 8: <table>
for Joined Objects Uses Dotted Path
<table>规则8:连接对象的<table>
使用带点的路径
<table>In , the element identifies which object in the join chain each column belongs to. For the base object, use the object name directly (e.g. ). For joined objects, use the dotted relationship path from the base object.
<sections><table>Account| Object in chain | |
|---|---|
| Base (Account) | |
| First join (Account → Contacts) | |
| Nested join (Account → Contacts → Assets) | |
在中,元素用于标识连接链中每个列所属的对象。对于主对象,直接使用对象名称(例如)。对于连接对象,使用从主对象出发的带点关系路径。
<sections><table>Account| 连接链中的对象 | |
|---|---|
| 主对象(Account) | |
| 第一层连接(Account → Contacts) | |
| 嵌套连接(Account → Contacts → Assets) | |
Rule 9: Field Paths Can Traverse Lookups
规则9:字段路径可遍历查找关系
<field>Owner.EmailReportsTo.CreatedBy.Contact.Owner.MobilePhone<table><field>Owner.EmailReportsTo.CreatedBy.Contact.Owner.MobilePhone<table>Rule 10: Historical Trending Fields Use _hst
Suffix
_hst规则10:历史趋势字段使用_hst
后缀
_hstFor a field with , the API name in and uses the suffix:
trackTrending=true<field><table>_hstxml
<columns>
<checkedByDefault>false</checkedByDefault>
<field>Field2__c_hst</field>
<table>CustomTrendedObject__c.CustomTrendedObject__c_hst</table>
</columns>对于的字段,和中的API名称需使用后缀:
trackTrending=true<field><table>_hstxml
<columns>
<checkedByDefault>false</checkedByDefault>
<field>Field2__c_hst</field>
<table>CustomTrendedObject__c.CustomTrendedObject__c_hst</table>
</columns>Rule 11: Primary Object Cannot Be Changed After Deployment
规则11:部署后主对象无法修改
Once deployed, the of a CRT is locked. To change the primary object, create a new CRT and retire the old one.
<baseObject>CRT部署后,将被锁定。如需修改主对象,需创建新的CRT并停用旧的CRT。
<baseObject>Rule 12: autogenerated
Is Reserved for Historical Trending
autogenerated规则12:autogenerated
为历史趋势专用
autogeneratedThe element (API 29.0+) marks CRTs that Salesforce created automatically when historical trending was enabled on an object. Do not set this manually on hand-authored CRTs.
<autogenerated><autogenerated>Generation Workflow
生成流程
Step 1: Gather Requirements
步骤1:收集需求
- Primary object API name (e.g. ,
Account)Project__c - Related objects and the relationship between each (which has the lookup/master-detail to which)
- For each relationship: inner join (children required) or outer join (children optional)?
- Which fields to expose per object — aim for task-relevant, not the full field list
- Audience and category — where should this appear in the report builder picker?
- Whether this ships as now or stays
deployed=trueduring iterationdeployed=false
- 主对象API名称(例如、
Account)Project__c - 相关对象及其相互关系(哪个对象拥有指向哪个对象的查找/主明细字段)
- 每个关系的类型:内连接(需要子记录)还是外连接(子记录可选)?
- 每个对象需要暴露哪些字段——目标是与任务相关的字段,而非完整字段列表
- 受众和类别——该CRT应出现在报表构建器选择器的哪个位置?
- 当前是否设置为供用户使用,还是设置为
deployed=true进行迭代deployed=false
Step 2: Examine Existing Examples
步骤2:查看现有示例
- Look in the project for in-project CRT patterns
- If existing report types have been retrieved from an org, compare against those structures
- 在项目中查找内部CRT模式
- 如果已从组织中获取现有报表类型,对比其结构
Step 3: Write the Specification
步骤3:编写规范
Document before authoring:
- and
fullNamelabel baseObject- Category and state
deployed - Join chain: for each related object — relationship name, outer vs inner join
- Section layout: one section per object, ordered list of fields
- Acceptance criteria: which records should appear when the report runs, which fields are available in the builder
在编写元数据前先记录:
- 和
fullNamelabel baseObject- 类别和状态
deployed - 连接链:每个相关对象的关系名称、外连接/内连接类型
- 节布局:每个对象对应一个节,字段有序列表
- 验收标准:报表运行时应显示哪些记录,构建器中可用哪些字段
Step 4: Author the Metadata File
步骤4:编写元数据文件
Start from the closest example in and adapt it to the user's scenario:
examples/- Primary object only (no joins) →
examples/AccountsWithIndustry.reportType-meta.xml - Outer join (primary records included even without children) →
examples/AccountsWithProjects.reportType-meta.xml - Nested inner join (every level requires children) →
examples/AccountProjectsWithTasks.reportType-meta.xml
Name the file .
<DeveloperName>.reportType-meta.xml从中最接近的示例开始,根据用户场景进行调整:
examples/- 仅主对象(无连接)→
examples/AccountsWithIndustry.reportType-meta.xml - 外连接(即使无子记录也包含主对象记录)→
examples/AccountsWithProjects.reportType-meta.xml - 嵌套内连接(每一层都需要子记录)→
examples/AccountProjectsWithTasks.reportType-meta.xml
将文件命名为。
<DeveloperName>.reportType-meta.xmlStep 5: Validate
步骤5:验证
- Well-formed XML with correct namespace ()
xmlns="http://soap.sforce.com/2006/04/metadata" - File name (without ) matches
.reportType-meta.xmlwhen<fullName>is included<fullName> - is a valid API name and the object is deployed
<baseObject> - Every uses the correct child relationship name (
<relationship>suffix for custom)__r - Each object referenced in is part of the CRT (primary or joined)
<sections> - All references exist on the parent
<field>and use API names (not labels)<table> - is a valid Salesforce category value
<category> - is
<deployed>if users need to access the CRT immediatelytrue
- XML格式正确,命名空间正确()
xmlns="http://soap.sforce.com/2006/04/metadata" - 当包含时,文件名(不含
<fullName>)与.reportType-meta.xml匹配<fullName> - 是有效的API名称且该对象已部署
<baseObject> - 每个使用正确的子关系名称(自定义关系以
<relationship>结尾)__r - 中引用的每个对象都属于CRT(主对象或连接对象)
<sections> - 所有引用都存在于父
<field>中,且使用API名称(而非标签)<table> - 是有效的Salesforce类别值
<category> - 如果用户需要立即访问CRT,设置为
<deployed>true
Reference File Index
参考文件索引
| File | When to read |
|---|---|
| Step 2 / Step 4 — primary-object-only template |
| Step 2 / Step 4 — outer-join template (primary included even without children) |
| Step 2 / Step 4 — nested inner-join template (every level requires children) |
| Step 3 — to choose a valid |
| When fields don't appear in the report builder or join requirements conflict |
| 文件 | 阅读场景 |
|---|---|
| 步骤2 / 步骤4 —— 仅主对象模板 |
| 步骤2 / 步骤4 —— 外连接模板(即使无子记录也包含主对象) |
| 步骤2 / 步骤4 —— 嵌套内连接模板(每一层都需要子记录) |
| 步骤3 —— 从 |
| 当字段未出现在报表构建器中或连接要求冲突时 |
Verification Checklist
验证清单
Universal Checks
通用检查
- File extension is
.reportType-meta.xml - File basename satisfies the developer-name rules (begins with a letter, only letters/numbers/underscores, no spaces, no trailing underscore, no consecutive underscores)
- If is included, it matches the file basename exactly (same characters, casing, and underscores)
<fullName> - is human-readable and under 40 characters
<label> - explains the business purpose
<description> - uses a valid API name and that object is deployed
<baseObject> - is a valid
<category>enum valueReportTypeCategory - is set appropriately (
<deployed>for user access,truefor in-progress iteration)false - is NOT set manually (reserved for historical-trending CRTs)
<autogenerated>
- 文件扩展名为
.reportType-meta.xml - 文件基名符合开发者名称规则(以字母开头,仅包含字母/数字/下划线,无空格,无末尾下划线,无连续下划线)
- 如果包含,其值与文件基名完全一致(字符、大小写、下划线均相同)
<fullName> - 易于理解且长度不超过40个字符
<label> - 说明了业务用途
<description> - 使用有效的API名称且该对象已部署
<baseObject> - 是有效的
<category>枚举值ReportTypeCategory - 设置合理(
<deployed>供用户访问,true用于迭代中)false - 未手动设置(为历史趋势CRT专用)
<autogenerated>
Join Checks
连接检查
- Each uses the correct child relationship name (not the lookup field API name)
<join> - Custom relationships use suffix
__r - is set intentionally:
<outerJoin>= optional children,true= required childrenfalse - No inner join () appears after an outer join earlier in the sequence
<outerJoin>false</outerJoin> - Total object count (base + joins, including nested) is 4 or fewer
- 每个使用正确的子关系名称(而非查找字段API名称)
<join> - 自定义关系使用后缀
__r - 设置符合预期:
<outerJoin>= 子记录可选,true= 子记录必填false - 序列中先出现外连接后,未出现内连接()
<outerJoin>false</outerJoin> - 对象总数(主对象 + 连接对象,包括嵌套)不超过4个
Section Checks
节检查
- Every object in the CRT has a corresponding block
<sections> - on each section is descriptive
<masterLabel> - Every has both
<columns>(API name) and<field>(object API name or dotted path)<table> - is set for each column
<checkedByDefault> - for base object is the object API name (e.g.
<table>)Account - for joined objects uses the dotted relationship path (e.g.
<table>,Account.Projects__r)Account.Projects__r.Tasks__r - Field references use API names (not labels); custom fields use
__c - Lookup traversal fields use dot notation (e.g. ) with
Owner.Emailset to the object owning the starting field<table> - Historical trending fields use suffix in both
_hstand<field>when applicable<table> - No duplicate fields within a section
- CRT中的每个对象都有对应的块
<sections> - 每个节的描述清晰
<masterLabel> - 每个都包含
<columns>(API名称)和<field>(对象API名称或带点路径)<table> - 每个列都设置了
<checkedByDefault> - 主对象的为对象API名称(例如
<table>)Account - 连接对象的使用带点的关系路径(例如
<table>、Account.Projects__r)Account.Projects__r.Tasks__r - 字段引用使用API名称(而非标签);自定义字段使用
__c - 查找遍历字段使用点符号(例如),且
Owner.Email设置为起始字段所属的对象<table> - 适用时,历史趋势字段在和
<field>中均使用<table>后缀_hst - 节内无重复字段