Specification
Salesforce Custom Report Type Metadata Knowledge
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.
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.
AccountsWithProjects.reportType-meta.xml
). Each CRT is a single file, not nested under an object folder.
Key Elements
| 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. , ). Cannot be changed after initial creation. All objects, including custom and external, are supported (external objects from API 38.0+) |
| Recommended | Report builder category — see references/category-values.md
|
| Yes | to expose to users; while building/iterating |
| Conditional | Adds a related object and its join behavior. Nest further blocks for deeper relationships |
| Recommended | Groups of columns available to the report type. Though not strictly required, a report without columns isn't useful |
(group of columns) sub-elements:
| Element | Required | Notes |
|---|
| Yes | Section heading shown in the report builder |
| Conditional | One per field exposed in the section |
(single field) sub-elements:
| 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 | if the column is selected by default in the report builder |
| No | Custom column label shown in the report builder, overriding the field's default label |
Critical Rules (Read First)
Rule 1: If Is Present, It Must Match the File Name
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.
Wrong — file name and
differ:
- File:
account_projects.reportType-meta.xml
<fullName>AccountProjects</fullName>
(Mismatch: file uses , fullName uses )
Right — file name and
are identical:
- File:
AccountProjects.reportType-meta.xml
<fullName>AccountProjects</fullName>
Rule 2: Join Semantics — Controls Inclusion
Each
block has an
element that determines which primary records appear in the report:
| value | 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.
Rule 3: Each Object Needs Its Own Block
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.
- on each section is the section heading in the report builder
- entries list the fields — each with a (API name) and (object API name)
- For fields reached via lookup, use the relationship path in (e.g. with set to the owning object)
Rule 4: Field API Names, Not Labels
Use exact API names for fields: standard fields use their defined names (
,
,
), custom fields use
. Custom objects must include
.
Wrong:
<field>Account Name</field>
Right:
Rule 5: Relationship Path for Joined Objects
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
.
Wrong:
<relationship>Project</relationship>
(for a custom child relationship)
Right:
<relationship>Projects__r</relationship>
(child relationship name)
<relationship>Contacts</relationship>
(standard, non-custom child relationship)
Rule 6: Maximum 4 Objects Total in a Join Chain
A single CRT can join a maximum of
four objects total (the base object + up to 3 additional objects via nested
blocks).
Rule 7: No Inner Join After an Outer Join
Once the join chain contains an outer join (
<outerJoin>true</outerJoin>
), 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.
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>
Rule 8: for Joined Objects Uses Dotted Path
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.
| Object in chain | value |
|---|
| Base (Account) | |
| First join (Account → Contacts) | |
| Nested join (Account → Contacts → Assets) | |
Rule 9: Field Paths Can Traverse Lookups
values may reference fields reached via lookup relationships using dot notation — for example
(owner User's email) or
ReportsTo.CreatedBy.Contact.Owner.MobilePhone
. The
must still be the object that owns the starting field.
Rule 10: Historical Trending Fields Use Suffix
For a field with
, the API name in
and
uses the
suffix:
xml
<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
Once deployed, the
of a CRT is locked. To change the primary object, create a new CRT and retire the old one.
Rule 12: Is Reserved for Historical Trending
The
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.
Generation Workflow
Step 1: Gather Requirements
- Primary object API name (e.g. , )
- 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 during iteration
Step 2: Examine Existing Examples
- Look in the project for in-project CRT patterns
- If existing report types have been retrieved from an org, compare against those structures
Step 3: Write the Specification
Document before authoring:
- and
- Category and state
- 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
Step 4: Author the Metadata File
Start from the closest example in
and adapt it to the user's scenario:
- 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
.
Step 5: Validate
- Well-formed XML with correct namespace (
xmlns="http://soap.sforce.com/2006/04/metadata"
)
- File name (without ) matches when is included
- is a valid API name and the object is deployed
- Every uses the correct child relationship name ( suffix for custom)
- Each object referenced in is part of the CRT (primary or joined)
- All references exist on the parent and use API names (not labels)
- is a valid Salesforce category value
- is if users need to access the CRT immediately
Reference File Index
| File | When to read |
|---|
examples/AccountsWithIndustry.reportType-meta.xml
| Step 2 / Step 4 — primary-object-only template |
examples/AccountsWithProjects.reportType-meta.xml
| Step 2 / Step 4 — outer-join template (primary included even without children) |
examples/AccountProjectsWithTasks.reportType-meta.xml
| Step 2 / Step 4 — nested inner-join template (every level requires children) |
references/category-values.md
| Step 3 — to choose a valid value from the enum |
references/errors-and-troubleshooting.md
| When fields don't appear in the report builder or join requirements conflict |
Verification Checklist
Universal Checks
Join Checks
Section Checks