How to Use the Transform Element in Flow

How to Use the Transform Element in Flow

Salesforce introduced the Transform element in the Winter '24 release. As its name suggests, this element transforms source data into a target data. Although you can already do this using Loop and Assignment elements, Transform element makes it much easier for the admins.

Here is how to use the Transform element in Salesforce Flow.

Adding a Transform Element

Transform element appears under the Logic section of the toolbox and it is available in all flow types.

Add a Transform Element

This element transforms your source data into a new target dataset. Therefore, after adding the element to the canvas, you have to select the resources to transform. It is possible to choose resources such as outputs from actions, record variables, and Apex-defined variables.

Transform Element Configuration

You can choose multiple source data by clicking the plus sign. However, you can choose only one target data (single or collection).

Source Data and Target Data Selection

Mapping the Data

After choosing the source and target data, you have to map the fields. In order to map the fields, you have to click on the circled bullet icons next to the fields. Then, choose the field to map from the target data.

Here is the mapping from a single Lead record to a single Contact record.

Mapping the Data

Field mapping supports formulas too. If you want to map a static value or enter a formula, you can build a formula directly from the Transform element. After mapping a field, choose the field, then click on the formula icon.

Build a Formula

Here you can build a formula for the mapping. Pay attention that the current item's format is [$EachItem]. For instance, here we have a collection of Contact records and the Title field for the current item is {!Get_Contacts[$EachItem].Title}.

Entering a Formula

Secondly, you can use a formula for static values as well.

Formula for Static Values in the Transform Element

Aggregate Calculations Using the Transform Element

Transform element supports aggregate calculations too. Instead of using Loop and Assignment elements, it is possible to use this element to count records or sum field values easily.

Firstly, choose a collection as the source data and a single record variable or a number variable as the target data.

For instance, let's calculate the total Opportunity amount. You have to click on the name of your collection (Get Opportunities), then choose a number field from the target record. If you want

Aggregate Calculation Mapping

Then, it will open the aggregate calculation screen. Here you can choose to count the records or sum field values.

Choosing Aggregate Type

If you choose to sum field values, you have to choose the field that you want to sum.

Choosing the Field to Sum

You can save the result directly to a new number variable too. For example, here it calculates the total number of Contact records and stores the result in a new number variable.

Save the Aggregate Calculation to a Number Variable

Another valuable use case of the Transform element is creating text collections. For example, you can use it to generate a text collection of record IDs. Read this post to see the full use case.

Creating a Text Collection

Output of the Transform Element

Transform element stores the mapped data in a new variable (single or collection). It always creates a new variable and it is not possible to choose an existing variable as the output.

For example, here is how to create the records from the output of this element.

Create Records

Example: Creating Opportunity Contact Roles for a New Opportunity

Let's build a record-triggered flow that creates Opportunity Contact Role records on Opportunity creation. Basically, we want to get all the Contact records of the related Account. Then, create Opportunity Contact Role records for each one of them.

There are 2 possible ways to build this flow.

First option is to use Loop and Assignment elements and then to create the records.

Loop and Assignment elements to Create Records

It is not wrong at all, it follows the best practices. However, now you can do it even faster using the Transform element.

Same Flow with Transform Element

Pay attention that since we need to map fields both from the Contact records and the current Opportunity record, we need to add 2 source data.

Transform Element Mapping

Summary

Salesforce introduced the Transform element in the Winter '24 release. This element can convert multiple variables to any type of single or collection variable. Moreover, it supports aggregate calculations as well. Although it is possible to accomplish these tasks using Loop and Assignment elements, the Transform element makes the configuration process much easier and faster.

2 Comments

3 Trackbacks / Pingbacks

  1. Using Data Table in Screen Flow to Display Non-Object Data - Salesforce Time
  2. New Flow Features of Summer '24 Release - Salesforce Time
  3. Sending Emails from Organization-Wide Email Addresses in Flow - Salesforce Time

Leave a Reply

Your email address will not be published.


*