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
nathanael.mnathanael.m 

Custom setting update exception

I'm getting the following error when updating a list custom setting that's part of a managed package:

 

Update failed. First exception on row 0 with id a0DA0000007MfC9MAK; first error: FIELD_INTEGRITY_EXCEPTION, There is already an item in this list with the name

 

I've only recently started seeing this and simply cannot see how this is possible. The code is very simple, retrieve the custom setting, change a field, and then update (not insert). Nowhere am I touching the id or name of the returned object. Example:

 

MySetting__c mysetting = MySetting__c.getValues('TestName');

mysetting.MyField__c = 'test';

update mysetting;

 

Any insights as to why this would happen?

Best Answer chosen by Admin (Salesforce Developers) 
spraetzspraetz

You may be running into this issue because there is currently a bug where if you do a bulk DML operation on a custom setting, you can get 2 custom settings of the same name in the DB.  We realized this issue recently and a fix has been scheduled for the Summer '11 release that will prevent this from happening going forward.

 

If that has happened, you could have another record in there with the same name as one you are working with.  When the update happens, it will run into the FIELD_INTEGRITY exception.

 

What you could do to fix it is remove any custom settings data with duplicate names.

 

Hope this helps.

All Answers

hisrinuhisrinu

This works fine for me when I tested with my custom setting. Is this the only code you are trying to execute or are you keeping this code as part of any loop?

 

 

Seems to be there is a duplicate values in the custom settings

nathanael.mnathanael.m

Thanks for responding. The above code is part of an action that's being invoked via an actionFunction. Technically this error shouldn't even be possible as I'm 'Updating' a record I just finished retrieving. I would completely understand the error if I were performing an insert.

 

Also of interest is the fact that I'm not seeing this behaviour in every org that our manage package is installed into.  So far I'm only seeing this behaviour in na7, which also doesn't make sense as it's a single code base... and yet I'm still getting this error...

 

Just a little stumped... :)

 

 

spraetzspraetz

You may be running into this issue because there is currently a bug where if you do a bulk DML operation on a custom setting, you can get 2 custom settings of the same name in the DB.  We realized this issue recently and a fix has been scheduled for the Summer '11 release that will prevent this from happening going forward.

 

If that has happened, you could have another record in there with the same name as one you are working with.  When the update happens, it will run into the FIELD_INTEGRITY exception.

 

What you could do to fix it is remove any custom settings data with duplicate names.

 

Hope this helps.

This was selected as the best answer
nathanael.mnathanael.m

Thanks, that was hugely helpful.

 

For anyone who might run into this before Summer '11 is released, here's the workaround I used per spraetz suggestion.

 

MySetting__c mysetting = MySetting__c.getValues('TestName');

mysetting.MyField__c = 'test';

 

try{

  update mysetting;

}catch(DML Exception e){

 

  List<MySetting__c> duplicates = [SELECT Id FROM MySetting__c WHERE Name='TestName' AND Id NOT IN :mysetting.Id];

if(duplicates.size() > 0)

  delete duplicates;

update mysetting;

 

}

BryanHartBryanHart

I'm still getting the problem as of winter13.

Its very rare (only seen it twice in the last 4 months or so). Try to upsert (single record) and it complains that the custom setting record already exists.

 

Did this ever get fixed?

wchoywchoy
Still hitting this issue as of Spring '15.
Very rare issue, reproducible on only one user in an environment.  We are trying to upsert (a single record) and it throws this error:

Upsert failed. First exception on row 0 with id; first error: FIELD_INTEGRITY_EXCEPTION, There is already an item in this list with the name.