Print this page

Inserting Custom List settings may insert multiple list settings with the same name

Knowledge Article Number 000176494
Description When inserting a custom list setting through a custom VF UI, you can bypass the validation on custom settings and insert multiple list settings records with the same name.  This causes apex failures on calls that expect unique settings names, such as the getAll() method, which returns a map with the name as key. 

To reproduce:

1.  Create a custom list setting called MyCustomSetting__c. 

2.  Create an apex controller with the following code:

public with sharing class CSController {
public PageReference save() {
       try{
            MyCustomSetting__c my_setting = new MyCustomSetting__c(Name = 'MyName');          
           insert my_setting;         
       }
         catch(Exception e){}
        return ApexPages.currentPage().setRedirect(true);
    }
    
public PageReference check() {
         map<string, MyCustomSetting__c> testMap= MyCustomSetting__c.getAll();
        return null;
}
}
Resolution Currently this is the system behavior and validation has to be done while inserting the list into custom settings. Make sure the list does not have duplicate names




promote demote