Sub topic 18
A decision guide for choosing a field type
This chapter assumes you know the individual field types from earlier chapters and can create fields in Object Manager. It gives you a repeatable order of questions for picking a type.
Ask the questions in this order
Work from the questions that rule out the most options to the ones that only fine-tune the choice.
- Is the value calculated or generated? Use a formula, roll-up summary or Auto Number field instead of asking users to type it.
- Does it point to another record? Use a relationship field.
- Is it a fixed set of choices? Use a picklist, a multi-select picklist or a checkbox.
- Is it a number, a date or text? Pick the narrowest type that fits.
Quick reference
| Requirement | Field type | Watch for |
|---|---|---|
| Short label, up to 255 characters | Text | Use Email, Phone or URL if the format matters |
| Long notes | Long Text Area | Cannot be used in filters or sorting |
| Money | Currency | Set scale for decimal places |
| Counts or scores | Number | Precision is total digits, scale is decimals |
| Yes or no | Checkbox | No third "unknown" state |
| One of a fixed list | Picklist | Compare with ISPICKVAL in formulas |
| Several of a fixed list | Multi-select picklist | Filter with INCLUDES in SOQL |
| Total of child records | Roll-up summary | Master-detail only |
| Sequential identifier | Auto Number | Read-only, assigned by the system |
Decisions that are hard to undo
Some choices cost more to change than others:
- Lookup versus master-detail. Master-detail makes the child inherit the parent's sharing and deletes children with the parent. It also lets you add roll-up summary fields. Choose it only when the child cannot exist without the parent.
- Text versus a specific type. A Text field holding numbers cannot be summed or sorted numerically. Converting it later can lose values that do not parse.
- Picklist versus free text. A picklist keeps reporting clean. Free text invites spelling variants.
When a lookup cannot host a roll-up summary field, compute the total in code:
List<AggregateResult> totals = [
SELECT AccountId, SUM(Amount) total
FROM Opportunity
WHERE AccountId != null
GROUP BY AccountId
];
for (AggregateResult ar : totals) {
System.debug(ar.get('AccountId') + ': ' + ar.get('total'));
}Common mistakes
- Using a Text field for phone numbers or emails, which loses validation and click-to-act behavior.
- Using a multi-select picklist for data you need to report on heavily. Each combination of values counts as a separate group.
- Choosing a Number field's precision too small, then discovering larger values do not fit.
Exercise
You need a field on Opportunity Line Item records that shows the total quantity across all line items on the parent Opportunity. Line items are children in a master-detail relationship. Which field type do you use, and on which object?
Show answer
A roll-up summary field on the parent Opportunity, because it is the master side of a master-detail relationship. It can summarize the Quantity field of the line items. If the relationship were a lookup, you would need an aggregate query or other automation instead.