Newer Version Available
Try It Out: Create Roll-Up Summary Fields
Begin creating your roll-up summary just as you create any other custom field:
- From Setup, enter Objects in the Quick Find box, then select Objects.
- Click Job Application.
- In the Custom Fields & Relationships related list, click New.
- 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.
- In the Field Label field, enter Total Rating. Once you move your cursor, the Field Name text box automatically populates with Total_Rating.
- Click Next.
- In the Summarized Object drop-down list, choose Reviews.
- Under Select Roll-Up Type, select SUM.
- In the Field to Aggregate drop-down list, select Rating.
- Leave All records should be included in the calculation selected, and click Next.
- Accept all remaining field-level security and page layout defaults.
- 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.
- From Setup, enter Objects in the Quick Find box, then select Objects.
- Click Job Application.
- In the Custom Fields & Relationships related list, click New.
- Select the Roll-Up Summary data type, and click Next.
- 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.
- Click Next.
- In the Summarized Object drop-down list, choose Reviews.
- 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.
- Leave All records should be included in the calculation selected, and click Next.
- Accept all remaining field-level security and page layout defaults.
- 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.
- From Setup, enter Objects in the Quick Find box, then select Objects.
- Click Job Application.
- In the Custom Fields & Relationships related list, click New.
- Select the Formula data type, and click Next.
- In the Field Label field, enter Average Rating. Once you move your cursor, the Field Name text box automatically populates with Average_Rating.
- Select the Number formula return type and click Next.
- Click the Insert Field button.
- Select Job Application >, then Total Rating, and click Insert.
- Click the Insert Operator button and choose Divide.
- Click the Insert Field button again.
- Choose Job Application >, then Number of Reviews, and click Insert. Your formula should look like this:
1Total_Rating__c / Number_of_Reviews__c - Click Next.
- Accept the defaults in the remaining steps of the wizard.
- 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.