You need to sign in to do that
Don't have an account?
Szymon
Access list custom setting data
I need to access ALL data sets in a list custom setting rather than name a specific data set:
Tried the below but then the query will return an error:
Can someone help me out please?
CustomSettingName__c mc = CustomSettingName__c.getValues(data_set_name);
Tried the below but then the query will return an error:
list <CustomSetting__c> mc = CustomSetting__c.getAll().values(); Database.getQueryLocator([select Id FROM Case WHERE Country__c LIKE :mc.Country_Code__c]);ERROR: Variable does not exist: Country_Code__c
Can someone help me out please?
Or if you want to use like, you can put like
All Answers
Or if you want to use like, you can put like
Your code fails because mc is defined as a list, not CustomSettingName__c Object ifself. The variable Country_Code__c belongs to the Object, not the List, that's why the program cannot find it.
To fix the program, you can think the following steps:
1> Create a List of String which is used to collect all the Country_Code__c from your custom setting:
list<string> countryNames = new list<string>();
2> Do a for loop to add your values to the list:
for(CustomSetting__c c: mc){
countryNames.add(c.Country_Code__c);
}
3> Use the list with you query:
Database.getQueryLocator([select Id FROM Case WHERE Country__c IN : countryNames]);
Best regards,
Hank
Thanks!
Since you are getting only one record from custom setting, so doesn't look logical to use IN operatore.
See