About Roll-Up Summary Fields

Available in: Contact Manager, Group, Professional, Enterprise, Unlimited, Developer, and Database.com Editions

While your formula fields calculate values using fields within a single record, roll-up summary fields calculate values from a set of related records, such as those in a related list. You can create roll-up summary fields that automatically display a value on a master record based on the values of records in a detail record. These detail records must be directly related to the master through a master-detail relationship. For example, a custom account field called Total Invoice Amount displays the sum of invoice amounts for all related invoice custom object records in the Invoices related list on an account.

You can perform different types of calculations with your roll-up summary fields. You can count the number of detail records related to a master record, or 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.

Implementation Tips

Administration

  • 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
      Note
      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.
  • You may not be able to 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 does not encounter a formula field that results in “#Error!”. If your filter criteria uses a formula field that results in an error, no matches are returned for that filter criterion. For example, if your roll-up summary filter is “Formula Field equals 10” and two records contain errors while one contains the value “10” in that field, your summary only includes the record with the value “10.”
  • Salesforce does not recalculate the value of campaign roll-up summary fields when leads or contacts are deleted. Select the Force a mass recalculation on this field option on the edit page of a campaign roll-up summary field to manually recalculate the value.
  • Long text area, multi-select picklist, Description, system fields like Last Activity, cross-object formula fields, and lookup fields (such as the Product Code field) cannot be used 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.

Management

  • Roll-up summary fields cannot calculate the values of other roll-up summary fields except for account to opportunity roll-up summary fields, which allow you to calculate the values of opportunity roll-up summary fields.
  • Roll-up summary fields can calculate the values of formula fields if they do not contain cross-object field references or functions that automatically derive values on the fly, such as NOW or TODAY.
    Note
    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, but 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 if the record should be reassigned.
  • Roll-up summary fields 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 may take up to 30 minutes, depending on the number of records affected and other factors.
  • You are not prevented from creating roll-up summary fields that might result in invalid values, such as February 29th in a non-leap year. If an existing roll-up summary field results in an invalid value, the value is not recalculated , and the field will continue to display with an invalid roll-up summary icon (invalid_roll-up_summary) 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 values in the detail record are converted into the currency of the master record before calculating the final value and displaying it in the same currency as the master record.
  • 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 will prevent users from saving a record when doing so would invalidate a related record. For example, if the related master record has a validation rule that requires the roll-up summary field value to be greater than 100, and the user's change to the child record will put the value over 100, the user will not be able to 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.

Best Practices

  • 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. A validation error can display when saving either the detail or master record because the value in a roll-up summary field changes when the values in the detail records change.
  • 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 field will have the previous value because the parent record has not been updated. If you reference a roll-up summary field from a parent record, the roll-up summary field will always have the new value because that rule runs after the parent value has been updated.

    If you are trying to enforce a record limit of 25 on the parent roll-up summary field, when you add a new child record, your validation rule on the child object needs to 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.
  • Roll-up summary fields are affected by advanced currency management. If your organization enables advanced currency management, delete any currency roll-up summary fields on accounts that summarize opportunity values or 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 are not allowed in roll-up summary fields. This includes formula fields containing functions that automatically 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.
See Also:
Defining Roll-Up Summaries
Creating Custom Fields
© Copyright 2000–2013 salesforce.com, inc. All rights reserved.
Various trademarks held by their respective owners.