Sub topic 9
Designing the field layout
The field layout of a custom report type decides which fields report builders can see and which ones start out on a new report. This chapter covers sections, default columns, label overrides, lookup fields, and the mistakes that cause "missing field" complaints.
It assumes you can already create a custom report type (the previous chapter), and that you know primary and related objects and the difference between "A with B" and "A with or without B".
What the layout controls
A custom report type has two jobs. The object relationships decide which records appear. The field layout decides which columns those records can show.
The layout is a list of sections, and each section holds fields. When someone opens the report builder with your type, the Fields pane lists the sections in your order, with the fields you placed in each one.
- A field that is not in the layout cannot be added to a report, filtered on, or grouped by.
- A field that is in the layout can still be hidden from a user by field-level security.
- Adding a field to the layout does not change any data. It only changes what reports can reach.
Sections
Sections are groupings for the Fields pane. By default, Salesforce creates one section per object in the report type, named after the object. For an Accounts with Contacts type you get an Accounts section and a Contacts section.
You can change this in the layout editor:
- Rename a section so it makes sense to your users, for example "Account details" or "Primary contact".
- Create new sections and move fields between them.
- Reorder sections and the fields inside them.
A section is only presentation. It does not limit which object's fields it can hold, so you can group a few fields from the primary object and a related object into one section such as "Contact and ownership".
Group by what the report author is trying to do, not by object. Authors building a renewal report want "Renewal dates" together. They don't care which object each date lives on.
Choosing which fields to include
In the layout editor, the field list on the right shows the fields from every object in the report type. You drag fields into sections.
There are two sensible strategies:
- Start small. Put in the 15 to 30 fields that the target reports need. The pane stays readable, and you can add fields later.
- Start broad. Include everything and rely on users to search. This is faster to build, but the Fields pane becomes long, and users pick the wrong one of several similar fields.
For most teams, start small. Adding a field later is cheap. Removing a field after reports use it is not (see the maintenance chapter).
Leave out fields that are internal or confusing, such as integration IDs, system flags, and legacy fields kept for old data. The same applies to fields with misleading labels.
Fields from related objects through lookups
The layout editor has an Add fields related via lookup option. It lets you add fields from objects that are reachable by a lookup from an object already in the type, such as the Owner of an Account, or the Created By user of a Contact. Salesforce documents support for several levels of lookups, up to four.
This is how you avoid creating a larger object hierarchy just to show a user's name or an account's parent. The related fields show up in the Fields pane in a section named for the lookup, and you can drag them into your own sections.
Two limits to remember:
- Lookups add columns, not rows. They never change which records are returned. Only the join type decides that.
- A lookup field is only useful if the lookup is populated. If it is blank on a record, the related columns are blank for that row.
Checked by default
Each field in the layout has a Checked by default setting. When a user creates a new report with your type, every checked field starts as a column. Unchecked fields are available but must be dragged in.
Use this to give new reports a sensible start. Check the 5 to 8 fields almost every report needs, such as Account Name, Contact Name, and Owner. Leave the rest unchecked.
If every field is checked, a new report opens as a wall of columns. If none are checked, a new report starts with only a few default columns, and the author has to hunt for what to add.
Renaming field labels
You can edit the display label of a field inside the layout. This changes the label only in reports built on this type. The field's label on the object, page layouts, and other report types does not change.
Use it for two cases:
- Two fields with the same label appear in one type, such as "Name" from Account and "Name" from Contact. Rename them to "Account Name" and "Contact Name".
- A field has a technical label that business users don't understand.
Do not invent a different meaning in the report type label. If the label says "Region" and the object field is "Territory," users will compare reports against list views and wonder which one is right.
How the layout looks as metadata
The layout is stored in the sections element of the report type's metadata. Each columns entry names a field, the table it comes from, and its default state.
<?xml version="1.0" encoding="UTF-8"?>
<ReportType xmlns="http://soap.sforce.com/2006/04/metadata">
<baseObject>Account</baseObject>
<category>accounts</category>
<deployed>true</deployed>
<description>Accounts with or without contacts</description>
<join>
<outerJoin>true</outerJoin>
<relationship>Contacts</relationship>
</join>
<label>Accounts with or without Contacts</label>
<sections>
<columns>
<checkedByDefault>true</checkedByDefault>
<displayNameOverride>Account Name</displayNameOverride>
<field>Name</field>
<table>Account</table>
</columns>
<columns>
<checkedByDefault>false</checkedByDefault>
<field>Phone</field>
<table>Account</table>
</columns>
<masterLabel>Account details</masterLabel>
</sections>
<sections>
<columns>
<checkedByDefault>true</checkedByDefault>
<displayNameOverride>Contact Last Name</displayNameOverride>
<field>LastName</field>
<table>Account.Contacts</table>
</columns>
<columns>
<checkedByDefault>false</checkedByDefault>
<field>Email</field>
<table>Account.Contacts</table>
</columns>
<masterLabel>Primary contact</masterLabel>
</sections>
</ReportType>How the elements map to the editor:
| Metadata element | What it does in the editor |
|---|---|
| `sections` | One section in the Fields pane |
| `masterLabel` | The section name |
| `columns` | One field in that section |
| `table` | Which object the field comes from. `Account` is the primary object, and `Account.Contacts` is the related object reached through the Contacts relationship |
| `checkedByDefault` | Whether the field starts as a column in a new report |
| `displayNameOverride` | The renamed label used only in this report type |
Because the layout lives in metadata, you can build it in a sandbox, review the XML in version control, and deploy it. The deployment chapter covers that.
Fields and security
The layout is not a security boundary. A field in the layout is visible to a user only if their field-level security grants them read access. If it does not, the column is hidden from that user. Two people can open the same report type and see different Fields panes. A saved report shared with someone who lacks access shows that column as blank or omits it.
New fields are not always added automatically
When an admin adds a custom field to an object, the field may not appear in your custom report type automatically. The layout holds the list you chose. After creating a field that reports need, open the report type's layout and check that the field is present. Add it if it is missing. Make this a step in your field-creation checklist.
Common problems
| Symptom | Likely cause | Fix |
|---|---|---|
| Field missing for everyone | Not in the layout | Add it in Edit Layout |
| Field missing for one user | Field-level security | Grant read access, or accept it |
| Two columns both labeled "Name" | Default labels from two objects | Override the labels in the layout |
| New report opens with 40 columns | Too many fields checked by default | Uncheck all but the common ones |
| Lookup fields blank | The lookup is empty on the record | Fix the data, or use a different relationship |
| Report columns change after layout edit | Authors had used a removed field | Restore the field, or fix the reports |
Practical design checklist
- List three or four real reports the type must support.
- Write down the fields each report needs.
- Add those fields and no more, plus a few clearly useful extras.
- Group them into sections with business names.
- Rename duplicate or technical labels.
- Check by default only the common columns.
- Test as a non-admin user with a typical profile.
Exercise
A custom report type for Accounts with Contacts shows two fields both labeled "Name" in the Fields pane, and users keep choosing the wrong one. Also, a sales user can't see the Contact Email field that an admin sees. What do you change in the layout for the first problem, and where do you look for the second?
Show answer
For the first problem, edit the layout and override the display labels, for example "Account Name" and "Contact Name". The override applies only inside this report type. For the second, the layout is not the cause, because the field is in the layout for everyone. Check the sales user's field-level security on Contact Email, through their profile or permission sets, and grant read access if the user should see it.
Exercise
You add a custom field to Contact and want it available in the Accounts with Contacts custom report type. What do you do, and why can't you just assume it appears?
Show answer
Open the report type's layout editor and add the field to a section. A custom report type's layout is the list of fields you chose, so a new field may not be added to it automatically. After adding it, confirm that the target users have field-level security read access.