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.
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.
You can choose multiple source data by clicking the plus sign. However, you can choose only one target data (single or collection).
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.
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.
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}.
Secondly, you can use a formula for static values as well.
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
Then, it will open the aggregate calculation screen. Here you can choose to count the records or sum field values.
If you choose to sum field values, you have to choose the field that you want 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.
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.
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.
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.
It is not wrong at all, it follows the best practices. However, now you can do it even faster using the 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.
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.
very promising feature. Thanks a lot for a digest.
wonderful feature review. 10x a lot!