I have an external Id field called Unique_Identifier__c
which is a concatenation of two fields on this Custom SObject Recipient
. This field is created/populated at before insert.
I want to allow the user to update records and I do not want to create duplicates in the system. I am upserting a list of these Custom SObjects at before insert after looping through all Recipients who have a match between their Unique Identifier and what is in the map.
When I go to upsert it is
- updating records that match with the Unique Identifier and
- creating duplicates
Why is my upsert creating duplicates if I am giving the External Id to match Recipients on? Should I be doing this in before insert? When replacing upsert with update it is also creating duplicates.