Newer Version Available

This content describes an older version of this product. View Latest

Try It Out: Create Roll-Up Summary Fields

Begin creating your roll-up summary just as you create any other custom field:

  1. From Setup, click Create | Objects.
  2. Click Job Application.
  3. In the Custom Fields & Relationships related list, click New.
  4. Select the Roll-Up Summary data type, and click Next.

When creating a field on an object that is not the master in a master-detail relationship, the Roll-Up Summary data type is not available. This is because roll-up summary fields are only available on the master object in a master-detail relationship.

  1. In the Field Label field, enter Total Rating. Once you move your cursor, the Field Name text box automatically populates with Total_Rating.
  2. Click Next.
  3. In the Summarized Object drop-down list, choose Reviews.
  4. Under Select Roll-Up Type, select SUM.
  5. In the Field to Aggregate drop-down list, select Rating.
  6. Leave All records should be included in the calculation selected, and click Next.
  7. Accept all remaining field-level security and page layout defaults.
  8. Click Save.

Now our job application records aggregate the ratings of their related reviews. This data could be a little deceptive, though, since some job applications might get reviewed more than others. It would be more helpful if we could see the average rating.

Roll-up summary fields themselves don't allow you to average values together, but you can use them in formulas that do. Let's create a second roll-up summary field on the Job Application object, and then build a simple formula field that uses both roll-up summary fields to find the average rating.
  1. From Setup, click Create | Objects.
  2. Click Job Application.
  3. In the Custom Fields & Relationships related list, click New.
  4. Select the Roll-Up Summary data type, and click Next.
  5. In the Field Label field, enter Number of Reviews. Once you move your cursor, the Field Name text box automatically populates with Number_of_Reviews.
  6. Click Next.
  7. In the Summarized Object drop-down list, choose Reviews.
  8. Under Select Roll-Up Type, select COUNT.

We don't need to specify a Field to Aggregate this time since we're just counting the number of related detail records and are not interested in any specific field.

  1. Leave All records should be included in the calculation selected, and click Next.
  2. Accept all remaining field-level security and page layout defaults.
  3. Click Save.

Both roll-up summary fields are in place now. Let's build a formula field called Average Rating that divides the value of the first roll-up summary field by the value of the second.

  1. From Setup, click Create | Objects.
  2. Click Job Application.
  3. In the Custom Fields & Relationships related list, click New.
  4. Select the Formula data type, and click Next.
  5. In the Field Label field, enter Average Rating. Once you move your cursor, the Field Name text box automatically populates with Average_Rating.
  6. Select the Number formula return type and click Next.
  7. Click the Insert Field button.
  8. Select Job Application >, then Total Rating, and click Insert.
  9. Click the Insert Operator button and choose Divide.
  10. Click the Insert Field button again.
  11. Choose Job Application >, then Number of Reviews, and click Insert. Your formula should look like this:
    1Total_Rating__c / Number_of_Reviews__c
  12. Click Next.
  13. Accept the defaults in the remaining steps of the wizard.
  14. Click Save.

That wraps up all the fields and relationships we need to manage our reviews. Let's quickly organize the presentation of our fields and then test everything we've created.