Today I was working on some Apex code that was delivered to us by a third party contractor to our organization, and ran into a line of code that I have never seen before:
upsert certsToUpsert.values() Unique_Certificate_ID__c;
Can anyone tell me what exactly is going on here? I understand that the first part of the statement is saying to update all of the values in the map certsToUpsert, but I have no idea what this external id field is doing.
To complicate matters further, I need to make some edits that remove certain elements of this map before insertion.
I attempted to do this by creating a list from the certsToUpsert.values() return, iterating through them, and then adding the values that we should be upserting into another list that I then attempted to upsert. However, despite being the same values as are in the map originally minus the duplicates, I then get an error:
INVALID_FIELD, More than 1 field provided in an external foreign key reference in entity: Certificate__c: []
I have tried both including and not including this Unique_Certificate_ID__c with the DML statement, but regardless I always come back to that same error. Given that these are the same values, and that with the field included in the DML statement I believe I am doing essentially the same thing with just a few less elements attempted to be upsert, I do not understand how this is possible.
If anyone can tell me why this may be, it would be greatly appreciated, but if nothing else it would be great to know what exactly the inclusion of this field is changing regarding this DML statement.
I am happy to provide further code if it may help identified things but as the class is very dense I didn't want to vomit code everywhere if not needed.