Quick Tutorial 14: Add Basic App Logic — Add A Rollup Summary Field

In the last tutorial, you created a formula field to calculate Line Item Totals. In this tutorial, you implement some more common business logic: an Invoice Total summary field in the parent Invoice object. To create summary fields based on master-detail relationships in Force.com, you can use a roll-up summary field.

Prerequisites

You must complete Quick Tutorial 1: Build a Cloud App in 5 Minutes before continuing with this tutorial.

Step 1: Create an Invoice Total Field

To add a rollup summary field to the Invoice object:

  1. Log into your DE org.
  2. Navigate to the Setup area, then click Create | Objects | Invoice.
  3. In the Custom Fields & Relationships section, click New.
  4. Choose Roll-Up Summary as the data type, and click Next.
  5. For the Field Label field, enter Invoice Total, press Tab, and click Next.
  6. For the Summarized Object list, choose Line Items.
    • For the Roll Up Type field, choose Sum.
    • In the Field to Aggregate list, choose Line Item Total.

Qs14 rollup.png

Click Next, Next, and then Save.


Step 2: Try Out the App

To see the new field, click the Invoices tab and examine an Invoice. Notice the new Invoice Total field that rolls up the values from all of the detail Line Items.


Qs14 total.png

Step 3: Update the Invoice Page Layout

Look carefully at an Invoice detail page, the two new fields you recently added don't appear in the Line Items list. Indeed, you must add them to the Invoice layout. You already edited page layouts in Quick Tutorial 8: Customize a User Interface — Modify a Page Layout, see if you can figure out how to add the Unit Price and Line Item Total to the Invoices layout. When you're done, create a new invoice, add some line items, and make sure it looks something like this:

Qs13 layout.png

Next Steps