I've got a page that inserts/updates a custom setting record. I'm using upsert for this purpose but I've run into an error:

There is already an item in this list with the name 005700000037xJaAAI System.DmlException: Upsert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, There is already an item in this list with the name 005700000037xJaAAI: [Name]

Obviously this is happening because my upsert statement is attempting to insert the record when it really should be trying to update it.

Since there is no external Id field, what is the criteria Salesforce is using to determine if this should be an update or an insert?


I was under the assumption that it would default to the "Name" field. It looks like I can explicitly specify the name field by doing something like this:

upsert myCustomSetting Name;
  • Turns out explicitly setting name did fix it, I was running into a unrelated issue in the sandbox
    – NSjonas
    Commented Jun 8, 2015 at 18:58

1 Answer 1


By default if field is not specified then Salesforce uses ID field for upsert.

If you want to explicitly specify other field, it should be defined as external Id.

You may refer this post to understand more about upsert operation and external Id.

Update :

Explicitly using Name in upsert can fix it.

  • 1
    You can upsert custom settings by Name. I use this often.
    – sfdcfox
    Commented Jun 8, 2015 at 19:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .