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

Get a custom setting dynamically



I want to return value of a custom setting as a string.


For example




Is this achievable?


Or can I do via dynamic SOQL somehow?



query = 'SELECT '+ foo +' from MySetting__C where .......'

Then return just the String value for foo and not an sObject?

Best Answer chosen by Admin (Salesforce Developers) 

I just noticed the sObject api has a GET method. This solved my issue calling MyInstance.get(string) returns the Object that I want.


so my code is now



String environment = Parameters__c.getValues('default').Environment__c;
Setting_AppDefaults__c setting = Setting_AppDefaults__c.getInstance(environment);
return setting.get(settingName);