Here's the use case:
An external system dumps multiple new Benefit records into our system at once.
A process builder flow identifies it is the right kind of Benefit that needs a Code, so it launches a flow.
That flow looks at the Benefit to see what Product it needs a code for. It then looks for a "Code" record that has not been marked "used" that is associated to that Product (via a lookup field).
It finds one, dumps a value from that Code record onto the Benefit record, marks itself "used" and adds the Benefit ID to it's benefit lookup field, making itself an official junction object between Product and Benefit.
Clear as mud, yes? And it works! Great!
Until I add multiple Benefits at the same time that have the same Product. Then it does this:
It grabs a code from an unused Code record, drops it on all of the Benefits that match that Codes Product, but only associates one of the Benefits to the Code record...
If I do this with 100 different benefits with 100 different products, no problem. But with the same Product, it can't seem to handle that and uses the same code.
As you guessed, these codes are unique and cannot be reused... so. Hmmm. Thoughts?! Ideas? Pontifications?