Here is an abridged tutorial to custom settings in APEX:
How to create a custom setting
Let's say your API name is custSetting__c like you mentioned. We'll give this custom setting 3 columns, the RGB values for the color.
// Retrieving custom settings
Map<String, custSetting__c> colors = custSetting__c.getAll();
system.debug(colors.get('Magenta').red__c + ', ' + colors.get('Magenta').green__c +', ' + colors.get('Magenta').blue__c);
// Creating new colors
custSetting__c newColor = new custSetting__c(
Name = 'Teal',
red__c = 0,
green__c = 255,
blue__c = 255
);
insert newColor;
// Looping through colors from a custom setting
for (custSetting__c color : custSetting__c.getAll().Values()) {
system.debug(color.name);
}
Some considerations when using custom settings
Custom settings are stored in the cache and are readily available to all code, all the time. Because of this, there is a limit to how much data can be stored in custom settings. Be sure not to overload them.
Custom settings have historically been used for app configurations. SFDC has developed custom meta data types as a new way of storing this information so check those out as well. The big difference is that custom meta-data types are not stored in the cache and need to be queried using SOQL. Custom meta-data types DO NOT impact SOQL query limits.
If you do not need the data to persist permanently, consider using static lists or enums instead.