Rollup summaries and limits

When it comes to performing calculations on your data, the platform provides a number of options: reports, the Analytics API, dashboards, Apex Triggers, Visualforce, and Rollup Summaries. The Rollup summary option provides a code-free solution with the ability to apply some condition filtering. Rollup summary fields can then also be referenced and combined with other features such as formula fields and Validation Rules.

The key requirement is that there is a Master-Detail relationship between the detail records being summarized on the field being added to the master records, such as that between Race and Contestant. The following example will total the number of competitors that did not finish a given race (or DNF in Formula 1 terms).

Perform the following steps in the package org to try out this process:

  1. Create a DNF field on the Contestant object using the Checkbox field type.
  2. Create a Driver record for Charles Pic and add him to the Spa race via the Contestant object, checking the DNF field.
  3. Create a Total DNFs field on the Race object using a Rollup Summary field type. Select the Contestants object from the Summarized Object dropdown and COUNT as Rollup-Up Type and apply the Filter Criteria field, as shown in the following screenshot, to select only Contestant records with the DNF field checked:

Navigate to the Spa record and note that Total DNFs shows the value 1. Experiment by changing the status of the DNF field on the Driver records to see the value recalculate.

Rollup summaries provide a real-time calculation once configured. However, when creating or changing rollups, Salesforce states that it can take up to 30 minutes. You can read more about them by searching for About Roll-Up Summary Fields in the documentation and by reviewing the Roll-Up Summary Field technology overview knowledge base article at http://help.salesforce.com/apex/HTViewSolution?id=000004281.

You can combine the use of Rollup summary fields in your Apex trigger logic; for example, you can add the Apex logic to check the number of DNFs in the after phase of the trigger on the Race object. Your users can also apply Validation Rules on the Race object that references its Rollup summary fields. Any changes to Contestant detail records that cause this Validation Rule to be invalid will prevent updates to the related Contestant record.

As you can imagine, calculating Rollup summaries can be quite an intensive job for the Salesforce servers. As such, Salesforce limits the total number of Rollup summaries to 25 per object, though this can be increased to 40 by contacting Salesforce Support with a valid business case. Keep in mind that, as a packaged application provider, this limit is not scoped by your namespace, unlike other limits. This means that if you use all 10, your end users will not be able to add their own post-installation. Similarly, if they have created their own post-installation and an upgrade causes the limit to be breached, the install will fail.

While this can be a powerful feature, carefully consider other summarization options listed in the previous paragraph and whether your users really need this information in real time or to be accessible from formulas and Validation Rules. If not, a good compromise is a Visualforce page, which can be added inline into the Page Layout objects. The Visualforce page can utilize the readonly=true attribute in which the Apex controller logic can utilize aggregate SOQL queries to aggregate up to 5 million records (subject to appropriate indexes and within standard timeout tolerance). This page can then display when the user reviews the record in the UI and is thus calculated on demand. Enhancing standard Salesforce pages with Visualforce is discussed in more detail later in this chapter.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.22.107