6

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?

UPDATE

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;
1
  • Turns out explicitly setting name did fix it, I was running into a unrelated issue in the sandbox – NSjonas Jun 8 '15 at 18:58
8

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
  • 1
    You can upsert custom settings by Name. I use this often. – sfdcfox Jun 8 '15 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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