Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What can be the use of an external ID field, not marked as unique? Helps in indexing?

I checked the documentation , and found that to upsert records with an external ID, there is no requirement that the external ID be unique. So, if I upsert records using a non-unique external ID, will I not get error saying "Duplicate External IDs" found? If not, how will the upsert pick records that have duplicate values in this external ID field?


share|improve this question
is there a documentation which says this? – Dharshni Feb 7 '14 at 12:11
To my knowledge, there is not benefit other than trying to mark a field as External ID so that it is indexed and searchable. But if you want it to truly uniquely identify the record then you need to also mark the field as Unique. – Doug Ayers Apr 16 at 20:37

Unfortunately you are right, using external IDs can lead to multiple matches during upsert operations.. taken from the documentation on Upserting examples:

If the key is matched multiple times, then an error is generated and the object record is neither inserted or updated.

So in answer to your question, yes you will get an error! Frustrating as it is.

Edit: This would need checking, but there is a specific exception type DmlException, which I imagine is what would be thrown, and you could (and probably should anyway) look to catch after an upsert call

    upsert yourList;
catch (DmlException e)
    // Report your error and/or try to re-handle the list?

Edit 2(!): Don't forget of course as well you can set your external ID to have unique (and case sensitive, and required) properties, which I would personally recommend if you ever intend on using the field in upsert commands.


share|improve this answer
/@sathya, do you know of a scenario where a duplicate EID would be needed/useful? – Bartley Feb 7 '14 at 12:48
The problem with the unique attribute is that it can't be turned on if it would be violated by existing non-null values. This is particularly a problem with data that already exists in the database that is marked as "external id" sometime after its creation. In that case, you have to first fix up the values so they are unique before enabling the unique attribute. External ID fields should always be marked as unique, but for practical purposes, sometimes it can't be because of dirty data. – sfdcfox Feb 7 '14 at 18:06

Have you tried doing the upsert operation to see what it actually does when you don't mark it as unique? If this is an issue for you, when you create the externalId field you can set it to be a unique identifier and I'm pretty sure it behaves just like the Id field would when upserting.

share|improve this answer

To avoid duplicate external id error, you can set the batch size to 1 so that it performs an operation on one row at a time and you can overcome this error.

share|improve this answer
This is incorrect, it would only 'solve' issues where the same id is present multiple times in the same source file, but not when multiple records in your destination org have the same external id. – Robin De Bondt May 27 '15 at 9:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.