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 the source data to the target data. 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, which can be a record variable or Apex-defined variable (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 as the target data. Transform element stores the final calculation in a field of the target data. Therefore, you will need to choose a number field on the target data to store the final calculation.

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.

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

Output of the Transform Element

Transform element stores the mapped data in a new record variable or Apex-defined variable (single or collection). It is not possible to choose an existing variable as the output. Even if you use this element for an aggregate calculation only, it will still store the output in a new variable.

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


Salesforce introduced the Transform element in the Winter '24 release. This element can convert any record or Apex-defined variable to any type of record or Apex-defined 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.

1 Trackback / Pingback

  1. Using Data Table in Screen Flow to Display Non-Object Data - Salesforce Time

Leave a Reply

Your email address will not be published.