LightningFlowComponents icon indicating copy to clipboard operation
LightningFlowComponents copied to clipboard

compare existing records with records to insert

Open cadillacben opened this issue 3 years ago • 5 comments

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.

cadillacben avatar Mar 02 '22 22:03 cadillacben

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.

cadillacben avatar Mar 03 '22 15:03 cadillacben

@jmdohn I seem to remember the original version supporting this scenario, do you know if you tested this when you made updates to it?

adwhitesf avatar Apr 07 '22 20:04 adwhitesf

@cadillacben You can also use the Map collection action to clear the Id value instead of creating a loop in your flow.

ericrsmith35 avatar Apr 07 '22 22:04 ericrsmith35

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.

RudimentaryTest

I'd also like to make a test to explicitly cover this scenario in the test class to prevent a future regression.

jmdohn avatar Apr 07 '22 23:04 jmdohn

I've created a PR for the updates to cover this scenario.

jmdohn avatar Apr 14 '22 21:04 jmdohn