You need to sign in to do that
Don't have an account?
Custom settings initialization failing on package re-install if custom settings have been managed
If I install my managed beta package into a new developer org the installation works fine.
If I install, then uninstall and re-install the installation still works fine.
But if I install, use "Manage" to create an org instance of a custom setting object, then uninstall and re-install the re-install fails with errors like these:
Apex Classes(01pA0000000i0ux) benefitclaimedactionstest.test() System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, cvc.BenefitTrigger: execution of BeforeInsert caused by: System.DmlException: Upsert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: SetupOwnerId duplicates value on record with id: 00DA0000000Y0TO: []
It appears the unit tests run as part of the install process are failing because of this underlying code (in this one case only):
public class CustomSettings { public static DateConversionFactors__c getDateConversionFactors() { if (DateConversionFactors__c.getOrgDefaults() == null) { insert new DateConversionFactors__c(SetupOwnerId = UserInfo.getOrganizationId()); } return DateConversionFactors__c.getOrgDefaults(); } }
My best guess is that the uninstall is not cleaning up the data created when "Manage" was used completely and so the SetupOwnerId inserted here is being seen as a duplicate.
Does anyone have any experience of this problem or insight into how to avoid it?
Thanks,
Keith
Your guess is correct seems the data is not cleaned up or their is a bug in getOrgdefaults().
I can suggest two fixes.
1. I never use getOrgDefaults(), instead I use getInstance() to get best matching custom setting.
2. Try "upsert" instead of "insert" for creating new custom setting. It might be more safer to use.
Let me know if you still get the same error
I can confirm that the error still occurs using upsert.
And that using getInstance() doesn't help either though I take your point that its is the more appropriate method to use.
Another thing that I can suggest depends if your are using hierarchal custom settings. If yes then we can run tests as some other user and do something like this.
Now change the code to load custom settings as follows, I just changed the SETUP OWNER ID from ORGID to current USERID
I tried to do an isolation of apex test data from org data. This is normally a good practice to follow. Let me know if it works. System.runAs() for tests is explained in more details here : http://www.tgerm.com/2010/05/systemrunas-501-apex-query-rows.html
I am having this same problem. The Custom Setting object is global, so I am able to test creating the Organization-level object either via my code (which has worked in the past) or through the Salesforce UI. In either case, I get the same error:
duplicate value found: SetupOwnerId duplicates value on record with id: 00DA0000000bZCG
I never got this error. CustomSetting__c.getInstance(), always gives best and finest level of matching custom setting for Org/Profile/User. I suggest checking that for null before doing upsert.
I'm getting the same problem as reported at the start of the thread.
I'm retrieving the custom setting for a specific user via GetInstance and doing an upsert. Is this a known bug?
WVSavePerUserSettings__c myUserSettings = WVSavePerUserSettings__c.GetInstance(UserInfo.getUserId());
I don't have any problems in my development org. When I create a managed beta, and deploy this, I get the error in the deployed org. I also suspect that the managed beta uninstall is not cleaning up custom data correctly. Even so, I don't know why this code should fail with the same error;
Upsert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: SetupOwnerId duplicates value on record with id: 005A0000000hue7: []
Hi!
Sounds like it is fixed, see here: "With the Developer/Config sandbox refreshed, we are not able to create a default value for a hierarchy custom setting. When user tries to create it, it gets the error of Duplicate value found: SetupOwnerId duplicates value on record with id: xxxxxxxx" https://success.salesforce.com/issues_releases_view?release=180008002
Im getting the exact same problem. How do you fix it?
Same issue on *2* fresh sandboxes with Winter 14. Anyone has a work around? I will be contacting SFDC but I don't think I will get a solution very fast