Loading
Salesforce now sends email only from verified domains. Read More
Help Agent Performance DegradationRead More
Automate Your Business Processes
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Sum or Count Items in Collections with the Transform Element

          Sum or Count Items in Collections with the Transform Element

          Aggregate data from a source collection to calculate the sum or count of items in that collection, and assign the result to a target data field.

          Required Editions

          View supported editions.
          User Permissions Needed
          To open, edit, create, activate or deactivate a flow using all flow types, elements, and features available in Flow Builder, including Einstein and Agentforce for Flow: Manage Flow

          Before you begin, understand the structure of your source and target data, such as whether the data contains multiple levels of collections within other collections. Mapping fields in a collection requires rules to preserve data integrity. See Flow Element: Transform.

          Count the number of items in a source collection, or add the field values on each item in the source collection to calculate their sum.

          1. Add the Transform element to your flow.
            1. Enter the label, API name, and description.
            2. For Source Data, click the Add Resource button Add Resource button and select the flow resource to transform the data.
              Select a resource that references a collection to aggregate.
            3. For Target Data, click the Add Resource button Add Resource button and select the data type.
            4. If the target data is a collection, select Allow multiple values (collection).
            5. For a Record or Apex-Defined data type, select the Apex class or object for the target data that the Transform element generates.
              For example, if you specified that the target data is a collection and that the record data type is the Account object, the Transform element generates an account collection. If you didn’t specify a collection, the target data is a single account.
          2. Map the source collection to the target data field that’s a Number data type.
            1. Hover over a source collection and click the Map button Circled bullet.
            2. Next to a target data field that’s a Number data type, click the Map button Circled bullet.
              If a target field doesn’t have the Map button Circled bullet, you can’t map to it. When mapping fields in a collection, the source and target fields must be at the same hierarchical level in their respective resources. See Flow Element: Transform.
          3. For Aggregate Type, select Count or Sum.
          4. For Field to Transform, select the source data field on each item in the source collection to calculate the transformed value.
            This field is available only for the sum aggregate type.
          5. Save your flow.
          Example
          Example

          Let’s say you create a flow that retrieves data about company locations from an external system. The external data includes company locations and the number of employees per location. In the flow, you map the CompanyDetails source collection to the NumberOfLocations target data field that stores the transformed value.

          A mapping between the Location source data field and the NumberOfLocations target data field

          You configure the Transform element to count the number of company locations.

          Aggregate panel that shows Count as the selected option for the Aggregate Type field

          Next, you map the CompanyDetails source collection to the NumberOfEmployees target data field that stores the transformed value.

          A mapping between the Employees source data field and the NumberOfEmployees target data field

          You configure the Transform element to calculate the sum of employees for all locations.

          Aggregate panel that shows Sum as the selected option for the Aggregate Type field
           
          Loading
          Salesforce Help | Article