+ Start a Discussion
dke01dke01 

Get a custom setting dynamically

Hi,

 

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

 

For example

 

MyCustomSettingInstance.getValueForField('foo');

 

Is this achievable?

 

Or can I do via dynamic SOQL somehow?

 

Like

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) 
dke01dke01

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);