Formula, roll-up summary, flow or code for related-record calculations
Key Takeaway
A roll-up summary field totals or counts detail records onto their master record, but it can't reference a cross-object formula. Salesforce recommends considering declarative tools before custom code.
When a record needs a value that depends on related records, an app builder can use a formula, a roll-up summary field, a flow, or code. To pick one, you need to know what each option does and where its limits are.
What each option does
| What it does | Example | |
|---|---|---|
| Roll-up summary field | Shows a value on a master record that is calculated from field values in its detail records | A custom account field called Total Invoice Amount can show the sum of all invoice records in the account's Invoices related list. |
| Cross-object formula | Reads field values from a related record, rather than adding up many records | A formula on opportunities can reference fields on the associated account. |
| Flow | Declarative automation built with clicks, not code. It can automate broader processes and act on related records. | A flow can update all of an account's related contacts when the account is updated, or create a renewal opportunity when an opportunity closes. |
| Code | Fits when a requirement is something flows can't do naturally | Generating a PDF file |