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
Romeo MirzacRomeo Mirzac 

Problem with Custom Settings in Managed Package

I created a managed package and am working on deploying it.  When I deploy the package to my testing environment, I keep getting an error while trying to access a customsetting i created.  The error is:  System.LimitException: aplusf:DML currently not allowed.  

The problem is that my applicaiton is NOT generated the managed list, even though I put code in to add the managed list if its not found.  I'm including the code below that I put in the application.  If I MANUALLY create the customsetting managed list name then my app works fine.  Any thoughts as to why this isn't working in test?

try{
            objSettings = new aplusf__Settings__c();
            objSettings = aplusf__Settings__c.getValues(strSetting);
           
            If(objSettings ==null){
                //Need to create new settings
                upsert new aplusf__Settings__c(
                    Name=strSetting,
                    aplusf__EnableApplication__c=false,
                    aplusf__EnableDebugging__c=false,
                    aplusf__EnableRecordTypes__c=false,
                    aplusf__EnableHelpMessage__c=false
                    );
                objSettings = aplusf__Settings__c.getValues(strSetting);
            }
            EnableApplication=objSettings.aplusf__EnableApplication__c;
            EnableDebugging=objSettings.aplusf__EnableDebugging__c;
            EnableRecordTypes=objSettings.aplusf__EnableRecordTypes__c;
            EnableHelpMessage=objSettings.aplusf__EnableHelpMessage__c;
        } Catch(Exception ex){
            String strM = 'An error occurred trying to save settings: ' + ex.getMessage();
            objSettings.addError(strM);
        } finally {return;}
    }
Ankit AroraAnkit Arora
Check if your custom setting is public or protected. If protected then make it public (you've to delete the old one and create new one, as you can't change the accessibility once created) and try it again.