compare existing records with records to insert
collectionsprocessors FindCommonAndUniqueRecords
Can we compare existing records to records we want to insert? I am trying to do so for permission set assignments, but the assigned records aren't actually records so it is failing (Attempt to de-reference a null object). My goal is to use the flow to assign permission sets, but you can't reassign duplicate permission sets, so I need to remove any duplicates before insert.
I found a bit of a work around for this. When assigning your new record, give it a somewhat fake record ID. In my case for permission set assignment I gave it 0Pa4u00000xxxxxxxx. The compare then works as expected. Before insert you have to loop the collection and make that field empty though.
@jmdohn I seem to remember the original version supporting this scenario, do you know if you tested this when you made updates to it?
@cadillacben You can also use the Map collection action to clear the Id value instead of creating a loop in your flow.
I don't recall that particular scenario when I did my testing. It appears that the class checks specifically for the id of the sobject before getting the type. I've made the change in my org that will likely cover this scenario, but would like to do additional testing tomorrow.
I'd also like to make a test to explicitly cover this scenario in the test class to prevent a future regression.
I've created a PR for the updates to cover this scenario.