You need to sign in to do that
Don't have an account?
![Nisha Babu 8 Nisha Babu 8](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
How to store query in custom setting
Hi,
I have to construct a query based on the custom fields added in the custom setting and have to store in a field inside the custom setting?
Is it possible for the query to take the values defined in the custom settig dynamically?
Regards,
Nisha
I have to construct a query based on the custom fields added in the custom setting and have to store in a field inside the custom setting?
Is it possible for the query to take the values defined in the custom settig dynamically?
Regards,
Nisha
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_custom_settings.htm%23apex_System_ListCustomSetting_instance_methods
Add your custom setting name in place of "CustomSettingName__c"
Map<String, CustomSettingName__c> config;
config = CustomSettingName__c.getAll();
String queryFields = 'Select Id,CaseNumber,ContactId,OwnerId,Owner.Name,Status,Origin';
for(CustomSettingName__c m : config.Values()) {
queryFields = queryFields + ',' + m.Name;
}
system.debug('*********'+queryFields);
queryFields = queryFields + ' ' + 'from Case';
system.debug('*********'+queryFields);
Please let me know if this solution works.