Perform Aggregation with Flow Transform (Sum / Count)

Quick guide: use the Flow Transform element to perform aggregate operations (sum, count) without loops by exposing Apex @AuraEnabled properties to Flow.

Overview

The Flow Transform element (Summer ’24 onward) lets you perform collection transforms such as sum, count, min, max and grouping. Instead of looping through a collection in Flow, you can expose an Apex class with @AuraEnabled properties to receive aggregated values directly in Flow. This simplifies automations and reduces the number of Flow elements needed.

Why this matters

Aggregations in Flow help you calculate totals, counts or other metrics from record collections without building manual loops. This leads to:

  • Cleaner Flow diagrams
  • Better performance for large collections
  • Easier maintenance and fewer elements

How it works (high-level)

1) Create an Apex class with public static properties or an inner wrapper marked @AuraEnabled.
2) Use Get Records to fetch the collection (for example, Accounts).
3) Configure the Transform element to reference the Apex type and the property to hold the aggregated value (Sum or Count).
4) The transform returns the aggregated value into your Flow variable — no loop required.

Minimal Apex example

Define a simple Apex type that Flow can reference; Flow reads/writes to the fields exposed with @AuraEnabled:

public with sharing class FlowAggregationResult {
    @AuraEnabled public Decimal totalEmployees;
    @AuraEnabled public Integer accountCount;
}

In Flow, you would:

  • Use Get Records to fetch Accounts (with NumberOfEmployees field).
  • Add a Transform element and select the Apex-defined type (FlowAggregationResult) and map the Sum operation on NumberOfEmployees to the totalEmployees field.
  • Optionally map a Count operation to accountCount.
  • Use the aggregated results in later Flow elements (assign, decision, update records).

Best practices

  • Always enforce field- and object-level security when building Flows that use Apex types.
  • Validate nulls — if numeric fields are empty, coalesce or handle default values in the Apex type or Flow.
  • Use transforms for simple aggregations; for complex grouping or calculations consider Apex or report-level aggregation.

Use cases

Common scenarios include: calculating total headcount across related accounts, summing order quantities before creating a summary record, or quickly returning record counts for conditional logic.

Conclusion

Using the Transform element together with a lightweight Apex type gives admins and developers a fast, maintainable way to perform aggregate operations inside Flows — removing the need for explicit loops and reducing flow complexity.

Why this matters for Salesforce admins, developers and business users: it reduces Flow complexity, improves performance, and makes aggregate calculations easier to maintain and reuse across automations.