Rollup Summary Fields and Flow Action
Most Salesforce implementations require rollup summary fields at some point. However, the native rollup summary fields are limited.
iDialogue includes a rollup summary flow action that handles most common rollup use cases encountered in document and content-driven solutions, such as generating complicated quotes, orders, and invoices.
Examples of using rollup summary fields:
- PDF Quotes with total amounts summarized by product type
- MRR and ARR summaries
- Account-based summaries for total active products by type, family, or product code
- Invoice amounts. Total paid. Total outstanding.
iDialogue implementations commonly deploy lots of rollup summaries. These rollup summaries in turn are merged into document templates or used in formula fields / flow conditions to determine the presence of absence of line item types and categories.
Features:
- Cross-object rollups. Example: Summarizing Total OrderItems on an Account record.
- Filters can be expressed using any SOQL WHERE syntax, with up to 5 hierarchical relationships.
- Unlimited rollup summaries per object.
- Easily deployed from sandboxes to production as a Custom Metadata Type.
iDialogue rollup summaries are extremely versatile and flexible. As long as there is a lookup relationship between any 2 objects, then any aggregate query of child records can be stored on parent summary fields.
Implementing Rollup Summaries
There are three components to Rollup Summaries:
- Custom number fields on Parent objects
- Rollup Summary Definitions
- Record-Triggered Flow Actions
Summary Fields
Create custom fields on parent objects to store the rollup values. These are commonly Number or Currency fields.
Example: to summarize the total number of subscription products on an Account record,
- Create a new custom field with naming convention that reflect what is being summarized
- Use data Number or Currency
- Define a default value (typically this is “0”)
- Define the number decimal places
Rollup Summary Definition
To create a rollup summary definition, go to Setup and search for “Custom Metadata Types”. Locate the custom metadata type “Rollup Summary Definition” and click on “Manage Records”.
Create a new Rollup Summary Definition with the following properties and definitions:
- Rollup Label
- Rollup API name. Important! This is the value used when retrieving rollup summaries in flows.
- Execution Policy. Leave as “Synchronous” (reserved for batch processes)
- Define the Parent Object.
- Define the API field name on parent object to be updated.
- Define the related child record type to be summarized
- Child parent lookup: the field that relates child to parent object
- Aggregate Operation (see below for details)
- Child Field to Aggregate. For COUNT aggregations, use “Id”. For “SUM”
- Query filter. Aggregates a subset of child records based on WHERE clause.
Rollup summary actions issue a SOQL Aggregate query under the covers. So any aggregate that can be accomplished using this API is also possible with the RSA.
- Use
COUNT
to summarize the total number of child records meeting filter criteria. - Use
SUM
on a currency field to get total amounts. - Use
MIN
andMAX
on number, date, or date time fields to get the lowest or highest value from the collection of child records. - Use
AVG
with any number or currency field to calculate an Average value.
Flow Action
Rollup summary fields are triggered via flows. Any flow type may initiate a rollup summary re-calculation. A record-trigger flow is the most common use case. But there are a variety of use cases and applications.
- Screen flows may invoke rollups at any point in a product configuration flow
- Schedule-Triggered Flows are useful for nightly batch operations, or mass updating summaries on many records.
- Autolaunched-Flows most often contain reusable process logic, and are a good option for invoking rollups.
- Record-Triggered flows commonly initiate rollup summaries in an AFTER update context.
- Platform Events. iDialogue implements an event-driven architecture that raises events for every customer interaction. These events can conditionally initiate a recalc of summary fields.
Update Opportunity Quote Summaries After Update
These steps describe how to update Opportunity number fields everytime a product is created or updated. The practical example might be summarizing the total number of recurring (subscription) vs one-time charges on a quote.
Start by creating a Record-Triggered Flow.
- Define the object that will trigger the rollup. Typically this is the child object in any parent-child rollup relationship.
- Best practice is to initiate the rollup calcs after create and update.
- To always trigger rollups, set the condition to “None”. If possible, use “Is Changed” conditions to only invoke this action when pertinent fields are changed. This will significantly improve org performance.
- Optimize the flow for AFTER action context. Choose the fast field BEFORE update option only in situations where other flows are waiting on real-time recalculations (such as a screen flow calling an auto-launched flow).
- When using the AFTER condition, then running the rollup summaries asynchronously ensures the record-trigger is not blocking.
Flow Elements
Most rollup summary flows require only one element, the “Rollup Summary Action” element. This is the only required element. The action will automatically retrieve all rollup definitions for a specific parent-child relationship and run the aggregate queries.
Flows may optionally GET a specific rollup summary definition (MDT metadata) record to be applied to the rollup.
The asynchronous branch is displayed in this diagram (see performance optimization points above). But either flow branch may execute the rollup action.
When adding an action element, search for “Rollup Summary Action” and add it to the flow.
Flow input parameters:
- Provide a flow label.
- Optionally provide a flow description.
- The parent record Id to be summarized (required). This is the $Record that initiated the flow.
- To fetch all rollup summary definitions of a particular child record type, define the object name here.
- To run one specific rollup summary definition, set the GET record here.
Note: Either (4) or (5) must be provided. But not both.
Testing and Troubleshooting
Once the flow is activated, create or update a record and validate the rollup fields on the parent object.
If the rollup fields are not summarizing as expected, then check the following:
- Review the rollup summary definition record. Are the object field names using the exact API name syntax? It’s useful to copy and paste field names into the definition to be certain.
- Is the COUNT aggregation type being used? If so, verify the Child Field to Aggregate is
Id
(no other fields can be used in a COUNT query). - Is there a query filter defined? If so, use Developer Console, or any query tool to verify the query contains valid syntax (yes, a declarative tool would be useful here. It’s on the way soon! -ML )
Finally, contact support@idialogue.app with any questions if the matter is not resolved.