A roll-up summary field calculates values from related records, such as those in a related list. You can create a roll-up summary field to display a value in a master record based on the values of fields in a detail record. The detail record must be related to the master through a master-detail relationship. For example, you want to display the sum of invoice amounts for all related invoice custom object records in an account’s Invoices related list. You can display this total in a custom account field called Total Invoice Amount.
Available in: both Salesforce Classic and Lightning Experience
Available in: Contact Manager, Group, Professional, Enterprise, Performance, Unlimited, Developer, and Database.com Editions
You can perform different types of calculations with a roll-up summary field. You can count the number of detail records related to a master record. Or, you can calculate the sum, minimum value, or maximum value of a field in the detail records.
Before you begin creating roll-up summary fields for your organization, review the implementation tips and best practices.
Create roll-up summary fields on:
Any custom object that is on the master side of a master-detail relationship
Any standard object that is on the master side of a master-detail relationship with a custom object
Opportunities using the values of opportunity products related to the opportunity
Accounts using the values of related opportunities
Campaigns using campaign member status or the values of campaign member custom fields
Campaign member custom formula fields that reference fields derived from leads or contacts are not supported.
The types of fields you can calculate in a roll-up summary field depend on the type of calculation. For example,
Number, currency, and percent fields are available when you select SUM as the roll-up type.
Number, currency, percent, date, and date/time fields are available when you select MIN or MAX as the roll-up type.
Sometimes you can’t change the field type of a field that you reference in a roll-up summary field.
Make sure that the filter for your roll-up summary doesn't encounter a formula field that results in “#Error!”. If one of your filter criteria uses a formula field that results in an error, no matches are returned for that filter criterion. For example, your roll-up summary filter is “Formula Field equals 10”. Two records contain errors, and one contains the value “10” in that field. In this case, your summary includes only the record with the value “10.”
When you delete a child record on a roll-up Summary field, Salesforce doesn’t recalculate the value of the field. Select the Force a mass recalculation on this field option on the edit page of the roll-up summary field to manually recalculate the value.
You can’t use long text area, multi-select picklist, Description fields, system fields like Last Activity, cross-object formula fields, and lookup fields in the field column of roll-up summary filters.
Auto number fields are not available as the field to aggregate in a roll-up summary field.
After you have created a roll-up summary field on an object, you cannot convert the object's master-detail relationship into a lookup relationship.
Roll-up summary fields are not available for mapping lead fields of converted leads.
If a roll-up summary field doesn’t contain cross-object field references or functions that derive values on the fly, such as NOW or TODAY, it can calculate the values of formula fields.
The value of a formula field can result in “#Error!”, which affects the summarized total. If your roll-up summary type is COUNT, records are included regardless of whether they contain a formula field with an error. However, when the Field to Aggregate is a formula field that results in “#Error!”, calculations of type MIN, MAX, and SUM exclude those formula values.
Changes to the value of a roll-up summary field can trigger assignment rules to run. If a roll-up summary field is part of the criteria in an assignment rule, the field’s new value is used to evaluate whether to reassign the record.
A roll-up summary field can trigger workflow rules and field validations. However, workflow rules and field validations do not fire when the following changes cause a mass recalculation of roll-up summary values:
Changing the roll-up summary definition (such as the object, function, or field being aggregated)
Changing the expression of a formula field referenced in a roll-up summary field
Replacing picklist values for picklist fields referenced in the roll-up summary filter
Changing picklist record type definitions
Changing currency conversion rates
Changing price book entries
Calculating roll-up summary field values can take up to 30 minutes, depending on the number of records affected and other factors.
You aren’t prevented from creating roll-up summary fields that can result in invalid values, such as February 29 in a non-leap year. If a roll-up summary field results in an invalid value, the value is not recalculated. The field continues to display with an invalid roll-up summary icon () until you change the values being summarized.
If your organization uses multiple currencies, the currency of the master record determines the currency of the roll-up summary field. For example, if the master and detail records are in different currencies, the detail record value is converted into the currency of the master record.
Changing a conversion rate triggers roll-up summary fields to recalculate. If you’re using multiple currencies, we recommend changing the conversion rate from Manage Currencies in Setup, and not from the API. If you change the rate from the API, related jobs that are less than 24 hours old can interfere with your change. For details, see Edit Conversion Rates.
If your organization has advanced currency management enabled, currency roll-up summary fields are invalid if they are on accounts and summarizing opportunity values, or on opportunities and summarizing custom object values.
Salesforce prevents users from saving a record if it invalidates a related record. For example, a master record has a validation rule that requires the roll-up summary field value to be greater than 100. If the user’s change to a related child record would put the value over 100, the user can’t save the record.
If a lookup field references a record that has been deleted, Salesforce clears the value of the lookup field by default. Alternatively, you can choose to prevent records from being deleted if they’re in a lookup relationship.
To be used in a roll-up summary field with a Roll-Up Type of COUNT or SUM, the lookup field must have the What to do if the lookup record is deleted? option set to Don’t allow deletion of the lookup record that’s part of a lookup relationship. If the option Clear the value of this field. You can’t choose this option if you make the field required is selected, you can’t create a COUNT or SUM roll-up summary field that pulls data from your lookup field.
Apply field-level security to your roll-up summary fields if they calculate values that you do not want visible to users. Fields that your users cannot see due to field-level security settings on the detail record are still calculated in a roll-up summary field.
If you have validation rules, consider how they affect roll-up summary fields. The value in a roll-up summary field changes when the values in the detail records change. So, validation errors can display when saving either the detail or master record.
Because roll-up summary fields are not displayed on edit pages, you can use them in validation rules but not as the error location for your validation.
Avoid referencing a roll-up summary field from a child record. The roll-up summary fields referenced from child records can have outdated values, because their parent records have not been updated. Instead, reference roll-up summary fields from parent records. Your roll-up summary fields will always have updated values, because that rule runs after the parent value has been updated.
If you’re trying to enforce a record limit of 25 on the parent roll-up summary field, create validation rules on your child objects. When you add a child record, your validation rule on the child object can check if the count is already 25 or greater.
AND(ISNEW(), Sample.Line_Count__c >= 25)
Plan your implementation of roll-up summary fields carefully before creating them. Once created, you cannot change the detail object selected or delete any field referenced in your roll-up summary definition.
Advanced currency management affects roll-up summary fields. If your organization enables advanced currency management, delete the currency roll-up summary fields on accounts that summarize opportunity values and on opportunities that summarize custom object values. Otherwise, the fields continue to display with an invalid roll-up summary icon because their values are no longer calculated.
Automatically derived fields, such as current date or current user, aren’t allowed in a roll-up summary field. Forbidden fields include formula fields containing functions that derive values on the fly, such as DATEVALUE, NOW, and TODAY. Formula fields that include related object merge fields are also not allowed in roll-up summary fields.
When you refer to a roll-up summary field in a list view or report, you can’t use certain qualifiers, including: