Sub topic 19
A Decision Guide for Choosing a Field Type
This chapter pulls the earlier chapters into one decision process. It assumes you know the basic data model (objects, records, fields), can navigate Setup and Object Manager, and have read the chapters on each field type. The aim is a repeatable way to pick a type, plus the checks that stop you from picking one you will regret.
Why the choice matters
Some field type decisions are cheap to reverse and others are not. Changing Text to Long Text Area is easy. Changing a lookup to master-detail needs every child record to have a parent. Changing a multi-select picklist back to a single-select can lose data. So decide carefully on the type attributes that are hard to change, and be relaxed about the ones that are not.
Step 1: Ask whether the user should type the value at all
Many fields should not be entered by hand. Check these first:
- If the value is derived from other fields on the same record, use a formula field. It is calculated when read and never goes stale.
- If the value is a total, count, minimum or maximum of child records, use a roll-up summary field. This works only on the master side of a master-detail relationship.
- If the value is a system-generated identifier such as
INV-0001, use Auto Number.
If none of these apply, the value is entered or imported, and you move to Step 2.
Step 2: Match the data shape
Use the table below to confirm your pick and to see the main limit or side effect of each type.
| Requirement | Type | Watch out for |
|---|---|---|
| Short label, up to 255 characters | Text | Can be indexed, filtered and used in a unique rule |
| Multi-line plain text, short | Text Area | Capped at 255 characters |
| Notes or descriptions, long | Long Text Area | Cannot be used in a SOQL `WHERE` filter, and is not sortable in list views |
| Formatted text with images or links | Rich Text Area | Stores HTML, so exports and integrations see markup |
| Count, measurement, score | Number | Set precision and scale up front |
| Money | Currency | Respects the org's currency settings and multi-currency |
| Ratio shown with a % sign | Percent | Stored as a number, shown as a percentage |
| Binary flag | Checkbox | No "unknown" state, so it is `false` by default |
| Calendar day | Date | No time zone conversion |
| Exact moment | Date/Time | Stored in UTC and displayed in the user's time zone |
| One of a managed list | Picklist | Use a global value set if several fields share values |
| Several of a managed list | Multi-select picklist | Awkward in reports and filters, so consider a junction object |
| Link to a parent | Lookup | Optional by default, and no roll-up summaries |
| Required parent with cascade delete | Master-detail | Child inherits sharing and cannot exist without the parent |
| Sensitive text | Encrypted Text | Reduced length, and limited use in filters and formulas |
Step 3: Test the choice against four questions
Before you save, check the choice against these:
- Will users filter, sort or report on it? Long Text Area fails this test. A multi-select picklist passes only partly. A picklist or a related object is usually better for reporting.
- Will another system load it? If so, add an external ID field of type Text, Number or Email. This lets upserts match on the other system's key.
- Does it need to be unique? Unique applies to text-like fields and can be case-sensitive or not. It also gives you an index.
- Could the value set grow or change? If yes, prefer a picklist or a related record over a checkbox or hard-coded text.
Common decision points
Picklist, multi-select or checkbox
Use a checkbox for one yes/no fact. Use a picklist when there is one answer from a list. Use a multi-select picklist only when users truly choose several values and you will rarely filter on them. If you need to report on each choice, or attach data to each choice, model it as a junction object instead.
Lookup or master-detail
Choose master-detail when the child has no meaning without the parent, you want cascade delete, you want the child to inherit the parent's sharing, or you need roll-up summaries. Choose lookup when the child can exist alone, the parent may change or be empty, or the child needs its own sharing. An object can have at most two master-detail relationships, which is why a many-to-many junction object uses exactly two.
If you need a total but must use a lookup, you can compute it in code instead:
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'));
}A scheduled job or trigger can then write the result to a Currency field on the parent.
Number precision and scale
Precision is the total number of digits and scale is how many fall after the decimal point. A field with precision 5 and scale 2 holds values up to 999.99. Pick the largest value you expect, then add headroom. Reducing precision later can fail or truncate data.
Text or picklist
If the same strings will be typed again and again, such as a region or a status, use a picklist. Free text invites typos like "N. America" and "North America", and those split your reports.
Checking what you built
After you create fields, confirm how Apex sees them. This catches surprises such as a Percent field reporting as PERCENT or a formula returning CURRENCY.
Map<String, Schema.SObjectField> fields =
Schema.SObjectType.Opportunity.fields.getMap();
for (String name : fields.keySet()) {
Schema.DescribeFieldResult d = fields.get(name).getDescribe();
if (d.isCustom()) {
System.debug(d.getName() + ' -> ' + d.getType());
}
}Changing your mind later
Safe changes are widening a Text field, moving Text Area to Long Text Area, and converting a single-select picklist to multi-select. Risky changes are anything that narrows length, turns text into a number or date, or turns a multi-select picklist into a single-select one. Formula fields that reference the field can block the change, so check dependencies first. For risky changes, create a new field, copy and validate the data, repoint the dependencies, then retire the old field.
A worked example
A team wants to track support contracts. Each contract has a customer, a start date, a term in months, an annual fee, a status, a list of covered products, a contract number, and a total of all contract fees per customer.
- Customer: a master-detail to Account, because contracts have no meaning without it and a total is required.
- Start date: Date, because no time of day matters.
- Term: Number with precision 3 and scale 0.
- Annual fee: Currency.
- Status: Picklist with Draft, Active and Expired.
- Covered products: a junction object to Product, since the team needs to report per product.
- Contract number: Auto Number.
- Total fees per customer: a roll-up summary on Account.
Exercise
A project object needs a field for a client's internal ticket key, such as "ABC-1042", which an integration sends every night. The key must not be duplicated and the integration should update existing records rather than create new ones. Which field type and attributes do you choose?
Show answer
Use a Text field marked as both Unique and External ID. External ID lets the integration upsert on the key, and Unique stops duplicates. Do not use Auto Number, because the value comes from the other system and not from Salesforce.
Exercise
You need the total of open case hours per Account, but Case is related to Account by a lookup. What are two ways to get the total?
Show answer
Convert the relationship to master-detail, which is only possible if the relationship is a legitimate fit and every case has an account, then add a roll-up summary. Otherwise compute the total with an aggregate query in Apex or a Flow and store it in a Number field on Account.