function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rabbani sayyed 8Rabbani sayyed 8 

What happens when 2 records have same external Id during an Upsert operation? can anyones share the answer for this?

KaranrajKaranraj
If the key is matched multiple times, then an error is generated and the object record is neither inserted or updated. Check here (http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_dml_examples_upsert.htm)for more details about upsert operation.
Vijay NagarathinamVijay Nagarathinam
When the two records have same external id means the first record will be upserted then the second record is not upsert, It throw some error message. Because of you have used the same external id in both records.

I think it will be helpful for you.
Brian Knezek 13Brian Knezek 13
Karanraj correctly answered the question that was asked, but to clarify for others who may be searching for answers...

Scenario 1
If two records already exist with the same External ID
, then trying to Upsert based upon that External ID will give the following error:
"[ExternalIDFieldName]: more than one record found for external id field: [recordID1, recordID2, etc.]"

Scenario 2
If one record exists, but you're making two Upserts to the same External ID with a batch update (like Data Loader)
, then both rows will get the following error: "Duplicate external id Specified: [externalIdValue]"

Exception: For Scenario 2, if you have set the data loader batch size to 1, then both updates will succeed, but the values set by the second upsert will overwrite the values set by the first upsert.
Azael Navarro JimenezAzael Navarro Jimenez
When you upsert and there are 2 same external ids; salesforce send you the total of rows that exists and give you the primary keys (salesforce ids) that you should you use to achieve upsert one bye one; in this case i upsert to 2 same external ids, but the API send me the 2 ids that i need to use to upsert one by one.

User-added image