Sub topic 14
Roll-up restrictions and per-object limits
This chapter assumes you can create a roll-up summary field on a master-detail relationship and can read a formula field definition. Roll-ups are powerful, but they have firm rules about where they can exist and what they can summarize. Knowing these rules up front saves you from redesigning a data model later.
Where roll-ups can exist
A roll-up summary field can only be created on the master side of a master-detail relationship. A lookup relationship cannot host one. If your child object is related by lookup, you need a different approach, such as the alternatives in a later chapter.
You can create a roll-up on a standard object, such as Account, only when that object is the master and the detail is a custom object with a master-detail field. You cannot add a roll-up field to a standard object's detail side.
Per-object limit
Each object can hold 25 roll-up summary fields by default. This limit counts every roll-up on the master object, whichever detail object it summarizes. Salesforce Support can raise the limit for an org, but plan your roll-ups with the default in mind.
What a roll-up can summarize
The summary type decides which field types you can choose.
| Summary type | Field types it can summarize |
|---|---|
| COUNT | No field needed. It counts detail records. |
| SUM | Number, currency, percent |
| MIN and MAX | Number, currency, percent, date, date/time |
Formula fields are valid targets only when they are simple. A roll-up cannot summarize a formula field that does either of these:
- It uses a function that derives a value from the current moment, such as
TODAY()orNOW(). - It references a field on another object.
The reason is that the roll-up stores its result. A value that changes without anyone editing a record would leave the stored total stale.
Dependency locks
Salesforce protects the fields a roll-up depends on. While a roll-up exists, you cannot delete the detail field it summarizes. You also cannot delete a field used in its filter criteria. You cannot change the data type of those fields either. Remove or edit the roll-up first, then change the dependency.
The master-detail relationship itself is also protected. You cannot convert it to a lookup while roll-ups depend on it.
Quick check before you build
Run through these questions before creating a roll-up:
- Is the relationship master-detail? If it is a lookup, a roll-up is not possible.
- Is the master object under its 25 roll-up fields?
- Is the field to summarize a supported type, and not a formula using
TODAY(),NOW(), or cross-object references? - Do you need a calculation that depends on the current date? If so, summarize a stable field and apply the date logic in a formula on the master.
Exercise
A team wants a roll-up on Account that sums a formula field on a detail object. The formula is Amount__c * (Close_Date__c - TODAY()). Will this work, and what should they change?
Show answer
It will not work. The formula uses TODAY(), so a roll-up cannot summarize it. They should roll up a stable field, such as Amount__c, and handle the date-based calculation in a formula field on the master object. If they cannot avoid the date logic on each detail record, they need Flow or Apex.