function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Adam ErskineAdam Erskine 

Comparing Flow Sobject Collections and Removing Dupes

Hello all,

I have a Custom Metadata type that stores records that are equivalent to "Tasks" and contains a few fields that hold criteria text for when these tasks should be created. 

In my Flow, I have a Get request for all Metadata records that match the input criteria, and then I loop through those Metadata records and assign each to a Task sObject variable and add them to a collection of Tasks for insert.  I include the Metadata Id field on a task field when I insert them.  This all works well.

The issue happens when I try to remove duplicate values from the Metadata because the Tasks are ALREADY EXISTING...

Here is what I tried to do:
  1. Find all the existing Tasks on object
    1. Get all Tasks
    2. Add to sObject Record Collection Variable (ExistingTasks) and capture Task Field "Metadata_Id__c" which = the SF Id of the Metadata
  2. Loop through ExistingTasks to get collection
    1. Each record is called ThisExistingTask
    2. Assign ThisExistingTask.Metadata_Id__c to a sObject Record Variable called ThisMetadata
    3. Add ThisMetadata record to a sObject Metadata record collection variable called ExistingMetadata
  3. Use the input criteria to Get the new Metadata
    1. Get Metadata records that meet the input criteria
    2. Add these to a Collection callend NewMetadata
  4. Loop through ExistingMetadata collection to remove from NewMetadata
    1. For each record in ExistingMetadata collection called ThisExistingMetadata
    2. Use an Assignment node to "Remove All" ThisExistingMetadata from collection NewMetadata
  5. //do more stuff

However, the Remove All assignment node is not removing the sObjects from the NewMetadata collection as I would anticipate.  

Can anyone please help?

Thanks,
Adam


 
Trina Banerjee 22Trina Banerjee 22
Hey Adam,
Did you end up figuring this out?? Having the exact same issue right now.
Adam ErskineAdam Erskine

Hi Trina,

I did not find a way to do this with a flow loop. 

I ended up making an invocable apex call in the flow that would upsert the tasks based on a unique identifier. That way the dml handles the duplicate existing tasks for me. 


hope this helps!

thanks,
Adam