Tuesday 7 May 2013


Roll-Up Summary Fields

Summarizing data in SQL databases is a routine matter of invoking GROUP BY and an
aggregate function like SUM. Force.com’s SOQL query language supports summarization
as well but comes with limitations. Built-in reporting in Force.com provides some summarization
functionality, but it’s an independent feature with its own user interface, not
integrated with your custom application’s user interface. For the flexibility to use summary
data anywhere, Force.com requires that it be calculated incrementally, either by the
database itself or in Apex code. As a result, planning for summary-level data as the database
is designed is best.
Roll-up summary fields are the mechanism for instructing the database that you would
like summary data to be calculated without custom code or ad-hoc queries.You specify

the child object to summarize, the function to apply to the child records, and filter criteria
on the child records.The database then takes care of keeping the roll-up summary values
up to date as child records are created, modified, and deleted. For example, given an
Invoice Header object and Invoice Line Item child object, you could use a roll-up summary
field on the Invoice Header to maintain a running count of invoice line items.
Roll-up summary fields are added to objects using the same process as adding other
types of fields.After you have provided a label and selected the Roll-Up Summary Field
type
The summary calculation consists of three parts:
Summarized Object: A drop-down list contains the objects you are permitted to
summarize.This is restricted to child objects in a Master-Detail relationship with
the object on which you’re creating the roll-up summary field. Lookup relationships
are not supported.

 Roll-Up Type: Select the calculation to be performed on the child records and the
field of the child object to perform it on.The fields available in this list depend on
the calculation. If your calculation is Sum, the list contains fields of type Number,
Currency, and Percent.With Min or Max, you can also summarize Date and
Date/Time fields. Note that you cannot roll up other roll-up summary fields or formula
fields that contain references to other objects, merge fields, or functions
returning dynamic values, such as TODAY and NOW.


Filter Criteria: By default, all records are included in the summary calculation.
Alternatively, you can also specify one or more filter criteria to restrict the records
involved in the calculation. Build filter criteria by selecting a field to filter, the
operator to apply, and the value. If you add more than one criteria, the effect is
additive. All filter criteria must be satisfied for the record to be included in the summary
calculation.

After you have specified the summary calculation and saved the new field, Force.com
begins calculating the summary values on existing records.This can take up to 30 minutes.
An icon is displayed beside the field to indicate that the calculation is running.
You can define at most ten roll-up summary fields per object. Make a point of creating
them toward the end of your database design process, because they make changing your
objects more difficult. For example, you can’t convert a Master-Detail relationship to a
Lookup relationship without first removing the roll-up summary fields.




No comments:

Post a Comment