I have created on custom setting whose API name is "testCustom__c" In that custom setting i have created one text area field whose API name is "FieldsToSearch__c". Now i have added one data set into that custom setting.

Name: "Fields"
FieldsToSearch: "Name,MobileNumber"

Now i want to get values which i have in FieldsToSearch in My apex class. How can i get this?


How about for hierarchical:

testCustom__c settings = testCustom__c.getInstance(); // for org wide
if( settings.Id == null ) settings = testCustom__c.getInstance(UserInfo.getUserId());
String fieldsToSearch = settings.FieldsToSearch__c;

You might also want to check for nulls first

or use SOQL for list (or hierarchy):

Select FieldsToSearch__c From testCustom__c;
  • I got this through SOQL but not using getInstance method. Is there any issue of profile. – Pankaj Jul 5 '13 at 10:55
  • Can you confirm what type of custom setting it is? – Phil Hawthorn Jul 5 '13 at 10:57
  • edited to add getting setting or a particular user – Phil Hawthorn Jul 5 '13 at 11:00
  • 3
    Be careful with checking settings == null. Need to check settings.Id == null because the no arg getInstance() returns a new object if nothing is defined. – Peter Knolle Jul 5 '13 at 11:05
  • What type means? – Pankaj Jul 8 '13 at 11:50

You can use the following if your custom setting is of list type.

map<string, testCustom__c> mMyCustomValues = testCustom__c.getAll();


List<testCustom__c> myCustomValues = textCustom__c.getAll().Values();

Once you have your list/map then loop through and check for values.

I don't believe there is an issue with profile is accessing the values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.