5.2 Roll-Up Summary Fields & Calculation Rules
Key Takeaways
Roll-up summary fields are exclusively available on the master object in a Master-Detail relationship to calculate COUNT, SUM, MIN, and MAX across child records.
Unlike formula fields, roll-up summary fields are physically stored in the master object's database table, enabling report/list filters and validation-rule references; storage does not itself guarantee an index.
Filter criteria on roll-up summary fields cannot reference cross-object formula fields or formula fields containing dynamic date/time functions like TODAY() or NOW().
Salesforce limits each object to 25 roll-up summary fields by default, which can be increased to a platform maximum of 40 by contacting Salesforce Support.
Modifying child records automatically recalculates master roll-up values synchronously, acquiring an exclusive database lock on the parent record that can lead to UNABLE_TO_LOCK_ROW errors in high-volume concurrent transactions.
Roll-Up Summary Fields & Calculation Rules
Roll-up summary fields represent the declarative gold standard for aggregating relational data in Salesforce. While formula fields perform scalar calculations on read, roll-up summary fields calculate aggregate metrics—such as sums, counts, minimums, and maximums—across sets of related child detail records and write those aggregated results directly onto the parent master record. Understanding the structural prerequisites, calculation triggers, and concurrency locking implications of roll-up summaries is essential for both the Platform App Builder exam and large-scale enterprise solution design.
Core Mechanics & Real-Time Aggregation
A Roll-Up Summary Field is a specialized, read-only field defined on the master object of a Master-Detail relationship. Whenever a detail record is created, edited, soft-deleted, undeleted, or reparented, the Salesforce database engine automatically recalculates the roll-up summary field on the associated master record.
Physical Persistence vs. Virtual Calculation
A critical architectural distinction between formula fields and roll-up summary fields lies in data persistence:
- Formula Fields: Evaluated on the fly at read time; values are not stored on disk.
- Roll-Up Summary Fields: Physically written to and stored in the master object's database table. Because the aggregated result is persisted as a static database value, roll-up summary fields:
- Can be used in queries; do not assume the field has a selective database index.
- Can be utilized as filtering criteria in list views and reports.
- Can be referenced in validation rules and Record-Triggered Flow entry criteria; verify field availability in each other feature.
- Do not incur read-time performance overhead when rendering large dashboards or querying parent records.
The Four Aggregation Operations: COUNT, SUM, MIN, MAX
Salesforce supports four specific mathematical aggregation functions within roll-up summary field definitions:
| Aggregation Function | Target Field Requirements | Supported Field Data Types | Common Business Use Cases |
|---|---|---|---|
| COUNT | None (counts records) | All child detail records | Total number of line items or custom milestone detail records attached to a project. |
| SUM | Mandatory | Number, Currency, Percent | Total revenue across invoiced orders, total hours logged across work tickets. |
| MIN | Mandatory | Number, Currency, Percent, Date, Date/Time | Earliest project milestone delivery date, lowest unit bid price submitted. |
| MAX | Mandatory | Number, Currency, Percent, Date, Date/Time | Most recent contract expiration date, highest discount percentage requested. |
Prohibited Target Field Data Types
Roll-up summary fields cannot aggregate text fields, long text areas, rich text, phone, email, URL, standard lookups, or picklists. If an organization needs to concatenate strings across child records (such as listing all asset serial numbers in a single text field on an Account), an app builder must implement a Record-Triggered Flow or programmatic Apex trigger.
Relationship Prerequisites & Standard Exceptions
Declarative roll-up summary fields enforce a strict architectural dependency: they can only be created on the master object in a Master-Detail relationship. If two objects are connected via a standard Lookup relationship, the "Roll-Up Summary" field type is disabled in the custom field creation wizard.
Standard Relationship Exceptions
While custom objects require a custom Master-Detail relationship, Salesforce provides several built-in standard relationships that support native roll-up summary fields even though they exhibit special platform behaviors:
- Account to Opportunity: Current Salesforce documentation explicitly lists Account roll-ups using related Opportunity values as a supported standard exception. Advanced Currency Management prevents currency roll-ups from Opportunities to Accounts; verify available fields and currency settings before choosing the design.
- Opportunity to Opportunity Product (
OpportunityLineItem): Opportunities can roll up product amounts, quantities, and dates from line items. - Campaign to Campaign Member: Standard Campaigns feature built-in roll-up statistics detailing total responses, converted leads, and won opportunities generated by campaign members.
Junction Objects and Many-to-Many Aggregation
In a many-to-many relationship constructed with a junction object, the junction object has two separate Master-Detail relationships pointing to two distinct master objects. Both master objects can independently host Roll-Up Summary fields that calculate metrics across the shared junction object records. For instance, in a Project Management app, a Project_Assignment__c junction object links Project__c and Consultant__c. The Project__c master can roll up total assigned consultant hours, while the Consultant__c master can roll up the total count of active project engagements.
Important
Converting Master-Detail to Lookup: If an app builder attempts to convert a Master-Detail relationship into a Lookup relationship, Salesforce will block the conversion if any Roll-Up Summary fields exist on the master object that reference the child object. All roll-up summary fields must be deleted from the master object before relationship conversion is allowed.
Roll-Up Summary Filter Criteria & The Formula Field Restriction
App builders can configure roll-up summaries to calculate across all child records or restrict calculation to a specific filtered subset of child records meeting defined criteria (e.g., SUM(Amount) where Stage = 'Closed Won' and Payment_Status__c = 'Verified').
The Strict Formula Field Restriction
A major focus of the Platform App Builder certification is the strict restriction governing formula fields inside roll-up summary calculations. A roll-up summary field cannot target or filter by a child formula field if that formula field:
- References a cross-object field (spans across a relationship to another object, such as
Product2.Family). - Contains a dynamic, volatile date/time function such as
TODAY()orNOW().
Child Formula contains TODAY() or spans to Parent ---> CANNOT be Rolled Up
Child Formula is deterministic (Quantity * Price) ---> CAN be Rolled Up
Why Does Salesforce Enforce This Restriction?
Consider what would happen if a roll-up summary field on Account rolled up all child Invoices where a formula field Is_Overdue__c (TODAY() > Due_Date__c) evaluated to TRUE. At midnight every night, thousands of invoices would flip from on-time to overdue simply because the calendar day changed—without any user or API updating the invoice records. Because no database DML transaction occurred, the platform would have no automated trigger to recompute the roll-up on the parent Account, resulting in stale, inaccurate data. To guarantee real-time mathematical integrity without requiring nightly batch recalculations across millions of database rows, Salesforce strictly disallows dynamic and cross-object formulas in roll-ups.
Deterministic formula fields—formulas that calculate purely mathematical operations using only static fields on the exact same child record (e.g., Line_Total__c = Unit_Price__c * Quantity__c)—are fully eligible for roll-up aggregation.
Platform Limits & Recalculation Triggers
- Default Object Limit: Salesforce enforces a default limit of 25 roll-up summary fields per standard or custom object.
- Support Increase: An organization can request an increase up to a hard ceiling of 40 roll-up summary fields per object by logging an operational case with Salesforce Support.
Recalculation Triggers
A roll-up summary field recalculates whenever any of the following database events occur on a related child record:
- Insert: A new detail record is created.
- Update: A field involved in the roll-up calculation (either the aggregated target field or a field referenced in the filter criteria) is modified.
- Soft Delete: A detail record is deleted and sent to the Recycle Bin. The master roll-up immediately recalculates, decrementing count or sum totals.
- Undelete: A detail record is restored from the Recycle Bin. The master roll-up immediately recalculates, restoring the aggregated metrics.
- Reparenting: If "Allow reparenting" is enabled on the Master-Detail relationship definition, changing the master record pointer on a child detail record triggers recalculation on both the former master record and the newly assigned master record.
Concurrency, Database Row Locking, and High-Volume Operations
In enterprise implementations with high transaction volumes, roll-up summary fields introduce critical database locking behaviors that app builders must design around.
Exclusive Row Locking Mechanics
When a child detail record is saved, the underlying database engine must ensure that the parent master record's roll-up summary field remains mathematically consistent. To accomplish this, Salesforce places an exclusive database row lock on the parent master record for the entire duration of the child record's save transaction. If child records are being updated sequentially, the lock is acquired, the roll-up is recalculated, the parent is updated, and the lock is released within milliseconds.
The UNABLE_TO_LOCK_ROW Exception
A concurrency failure occurs when multiple automated processes, external integrations, or parallel bulk data loads attempt to insert or update child records belonging to the same parent record simultaneously:
Thread 1 (Updating Child A) ---> Locks Parent Master Record (In Progress)
Thread 2 (Updating Child B) ---> Attempts to Lock Parent Master Record ---> Fails: UNABLE_TO_LOCK_ROW
Because Thread 1 holds an exclusive lock on the parent master, Thread 2 cannot acquire the lock within the platform timeout window (typically 10 seconds). The transaction aborts and throws a System.DmlException: UNABLE_TO_LOCK_ROW: unable to obtain exclusive access to this record error.
Architectural Mitigations for Bulk Data Loading
- Use Serial Mode in the Bulk API: When loading child records that share common parents (such as thousands of order line items pointing to a handful of master accounts), configure Data Loader or the Bulk API to process batches in Serial Mode rather than Parallel Mode.
- Pre-Sort Input Datasets by Parent ID: Sort child import files alphabetically by
ParentId. This reduces contention, but a large parent group can still span batches and other jobs can hold locks. - Architectural Decoupling via Record-Triggered Flows: For lookup relationships where master-detail is unviable, or to decouple non-immediate work in high-volume environments, app builders can implement scheduled or asynchronous Record-Triggered Flows with Scheduled Paths, or use tools like Declarative Lookup Rollup Summaries (DLRS).
Comparison: Roll-Up Summaries vs. Formula Fields vs. Flows
| Architectural Dimension | Roll-Up Summary Field | Cross-Object Formula Field | Record-Triggered Flow (After-Save) |
|---|---|---|---|
| Relationship Type | Master-Detail only (with standard exceptions) | Lookup or Master-Detail | Any relationship (Lookup, Master-Detail, Unrelated) |
| Calculation Direction | Downward (Parent rolls up Children) | Upward (Child surfaces Parent data) | Any direction (Parent, Child, Peer) |
| Data Persistence | Stored on Master database table | Virtual (Calculated on read; not stored) | Stored physically on target records |
| Platform Limit | 25 per object (support increase up to 40) | Subject to 15,000-byte compile limit | No hard count limit; governed by CPU / DML limits |
| Filtering / Indexing | Report/list filtering; not automatically indexed | Filtering supported; qualifying deterministic formulas may be indexed | Depends on target field and indexing |
| Dynamic Date Support | Prohibited (Cannot use TODAY() in criteria) | Fully supported | Fully supported |
Official Source Check
Checked October 19, 2026: Roll-up default and maximum allocations.
Checked October 19, 2026: Supported standard roll-up relationships and limitations.
Cloud Kicks wants to display the date of the most recently closed contract on the Account detail page. A custom Contract__c object is the detail of Account through a master-detail relationship. Which declarative solution should the app builder configure?
Create a cross-object formula field on Account using the MAX(Contract.Close_Date__c) formula function
Configure a before-save Record-Triggered Flow on Account that queries all child Contract records upon view
Deploy an Apex trigger on Contract that fires after insert, update, and delete, and executes an aggregate SOQL query with a GROUP BY clause inside a loop for every record processed in the transaction
Create a Roll-Up Summary field on Account using the MAX aggregate function on Contract__c Close_Date__c, filtered by Status equals 'Closed'
An app builder attempts to create a roll-up summary field on the custom Building__c object to aggregate the total rental income of related Apartment__c units. However, in the New Custom Field wizard, the "Roll-Up Summary" field type option is disabled (greyed out). What is the root cause of this behavior?
The Building__c object has already consumed its full allocation, because the platform enforces a hard limit of 10 roll-up summary fields per master-detail relationship pair, and this limit is shared collectively across every custom object in the org
The relationship between Building__c and Apartment__c is configured as a Lookup relationship rather than a Master-Detail relationship
The app builder's profile lacks the "Customize Application" administrative permission in Setup
The Apartment__c object contains active validation rules that prevent real-time roll-up calculation
An integration team is loading 100,000 Order Item records associated with 500 Order master records using the Salesforce Bulk API in Parallel Mode. The data load experiences widespread UNABLE_TO_LOCK_ROW error failures. What architectural root cause and remedy should the app builder identify?
The Order Item object has exceeded its maximum custom field allocation; convert the Master-Detail relationship to a Lookup relationship
Validation rules on the Order Item object acquire exclusive row locks while evaluating each incoming record, which blocks the parallel batches from committing; deactivate every validation rule on both objects and rerun the load in Parallel Mode so each batch thread commits its locked records independently of the parent Order
Parallel Bulk API threads are simultaneously attempting to update child records belonging to the same parent Order, which locks the master record to recalculate roll-up summary fields; process the load in Serial Mode or sort the import file by Order ID
The platform default limit of 25 roll-up summary fields was exceeded; review an increase up to 40 with Salesforce Support
Sections you finish are checked off in the contents.