A year ago, I showed you how you can use a Flow with a Loop and a special Apex action to update the Selected records from the Datatable component with the Edited records from the same Datatable.
Now I’m going to show you how you can get rid of the Loop and use a different action and a simple assignment to produce the same results.
My Datatable Flow Screen Component allows a user to both Select records and make Edits to records. The component returns two separate collection variables. One of them includes the original values of just the Selected records. The other one includes just the Edited records whether they were selected or not.
Sometimes, you may want to process just the selected records in your flow, but include the edited values in those selected records. This sample flow shows how you can create a selected record collection with edits. The flow uses the Get Common and Uncommon Records action that is part of the Collection Actions from UnofficialSF.com to compare the collections returned by the Datatable and extract the common and unique records from them.
Here’s a Datatable displaying all of the Product records from an Opportunity.
I’ll select 3 records and make edits to 2 of them.
My normal outputs from the Datatable include the original 3 selected records and a separate collection of just the edited records.
To create a record collection that combines these two requires just a couple extra steps in your flow. The magic happens in the Get Common and Uncommon Records Flow Action. This action takes two separate record collections, Source (Selected) and Target (Edited), along with a field from each (Id) that is used to match them up and returns 4 separate record collections.
- Source Common – Records from the Source collection that are also in the Target collection
- Source Unique – Records from the Source collection that are not in the Target collection
- Target Common – Records from the Target collection that are also in the Source collection
- Target Unique – Records from the Target collection that are not in the Source collection
First, I created a Record Collection variable for Opportunity Product that will be used to store the combined outputs from the Action.
I pass the outputs from the Datatable into the Get Common and Uncommon Records Action.
We are only going to use two of the output collections and they will be combined into a single collection of Selected records that include any of the Edits made to them.
- Source Unique – All Selected records that are not also Edited records
- Target Common – All Edited records that are also Selected records
An Assignment node is used to Add each of the desired collection outputs from the Action into our final record collection of selected and edited records.
As you can see in the Results Screen, the Selected Records are unique from the Edited Records, but the combined Selected Products with Edits includes all Selected with any Edits made to those records.