I have Set in my apex class as below

        Set<String> removeFields = new Set<String>{'isUpage','email','mobileno','owneremail','comments','Name','isApproved'};

I need to use these strings as custom settings because in future if i need to add any string to this list i can go through configuration instead of touching apex class

can anyone suggest me how to creates and get that custom setting values into set.


You could simply create a list custom setting (for example with API name CustomSettingName__c) and enter the values in standard Name field. The name field is also unique which does not allow a duplicate value.

Map<String, CustomSettingName__c> mcs = CustomSettingName__c.getAll();
Set<String> removeFields = mcs.keySet();

You can create a List Custom Setting or can use Custom Metadata and have all the values as records. Then when fetching the records, you can get the records from custom settings/custom metadata and convert those records into a set<string>

If you store these values as records in custom settings, where your name field will contain the value of string, then you can get those values as set directly using below method

Map<String, StringValues__c> stringValues = StringValues__c.getAll();
Set<String> removeFields = stringValues.keyset();

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.