0

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?

2 Answers 2

3

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;
6
  • I got this through SOQL but not using getInstance method. Is there any issue of profile.
    – Pankaj
    Commented Jul 5, 2013 at 10:55
  • Can you confirm what type of custom setting it is? Commented Jul 5, 2013 at 10:57
  • edited to add getting setting or a particular user Commented Jul 5, 2013 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. Commented Jul 5, 2013 at 11:05
  • What type means?
    – Pankaj
    Commented Jul 8, 2013 at 11:50
0

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

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

or

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .