When you add data to a custom setting, you must name each set of data. Then you can distinguish between the sets of data by the data set name. The following returns a map of custom settings data. The getAll method returns values for all custom fields associated with the list setting.
The following example uses the getValues method to return all the field values associated with the specified data set. This method can be used with both list and hierarchy custom settings, using different parameters.
CustomSettingName__c mc = CustomSettingName__c.getValues(data_set_name);
2) Hierarchy Custom Setting Examples The following example uses the getOrgDefaults method to return the data set values for the organization level
CustomSettingName__c mc = CustomSettingName__c.getOrgDefaults();
The following example uses the getInstance method to return the data set values for the specified profile. The getInstance method can also be used with a user ID.
CustomSettingName__c mc = CustomSettingName__c.getInstance(Profile_ID);
When you add data to a custom setting, you must name each set of data. Then you can distinguish between the sets of data by the data set name. The following returns a map of custom settings data. The getAll method returns values for all custom fields associated with the list setting.
The following example uses the getValues method to return all the field values associated with the specified data set. This method can be used with both list and hierarchy custom settings, using different parameters.
CustomSettingName__c mc = CustomSettingName__c.getValues(data_set_name);
2) Hierarchy Custom Setting Examples The following example uses the getOrgDefaults method to return the data set values for the organization level
CustomSettingName__c mc = CustomSettingName__c.getOrgDefaults();
The following example uses the getInstance method to return the data set values for the specified profile. The getInstance method can also be used with a user ID.
CustomSettingName__c mc = CustomSettingName__c.getInstance(Profile_ID);
I would suggest you to use Custom Metadata Types instead of custom Settings
Perhaps the biggest advantage Custom Metadata Types have over Custom Settings is that the data themselves are considered to be Metadata. So, essentially, you have Metadata about Metadata. Technically, they are called “Components”, and the reason this is important, is because you can DEPLOY the records!
Since the Records themselves are Metadata, they are refreshed to Sandboxes; even those with no data.
Since the Records themselves are Metadata, APEX Tests can see them even with “SeeAllData=False”. No more creating Custom Settings for Test Classes! • Custom Metadata
Types are more like a custom object than Custom Settings. This means it takes a little more time to create them, but you have more control such as page layouts and other features.
Starting with Winter ’16, like a custom object might have, you can Track Audit Trail history! This is a must have feature!
Like Custom Settings, Custom Metadata Types do not cost a SOQL when referencing them. Moreover, you can reference a Custom Metadata Type with a standard SOQL instead of using the special Custom Settings Class. For example: Select ID, Field1__c, Field2__c, … From My_CustomMetadataType__mdt
Like Custom Settings, all records are Cached. So you don’t need to worry about performance, and indeed, this will provide better performance over a normal table.
1) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_custom_settings.htm
2) http://amitsalesforce.blogspot.com/2014/11/dynamic-field-mapping-using-custom.html
1) Samples for List Custom Settings
When you add data to a custom setting, you must name each set of data. Then you can distinguish between the sets of data by the data set name. The following returns a map of custom settings data. The getAll method returns values for all custom fields associated with the list setting. The following example uses the getValues method to return all the field values associated with the specified data set. This method can be used with both list and hierarchy custom settings, using different parameters. Example 1:-
2) Hierarchy Custom Setting Examples
The following example uses the getOrgDefaults method to return the data set values for the organization level The following example uses the getInstance method to return the data set values for the specified profile. The getInstance method can also be used with a user ID. Example 2:-
Example 3:- Dynamic Query and map with Custom setting
Let us know if this will help you
Thanks
Amit Chaudhary
All Answers
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_custom_settings.htm
Hope this helps.
Please refer below link which has all the information.
https://help.salesforce.com/apex/HTViewHelpDoc?id=cs_accessing.htm&language=en
Please let us know if this helps you.
Thanks and Regards
Sandhya
1) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_custom_settings.htm
2) http://amitsalesforce.blogspot.com/2014/11/dynamic-field-mapping-using-custom.html
1) Samples for List Custom Settings
When you add data to a custom setting, you must name each set of data. Then you can distinguish between the sets of data by the data set name. The following returns a map of custom settings data. The getAll method returns values for all custom fields associated with the list setting. The following example uses the getValues method to return all the field values associated with the specified data set. This method can be used with both list and hierarchy custom settings, using different parameters. Example 1:-
2) Hierarchy Custom Setting Examples
The following example uses the getOrgDefaults method to return the data set values for the organization level The following example uses the getInstance method to return the data set values for the specified profile. The getInstance method can also be used with a user ID. Example 2:-
Example 3:- Dynamic Query and map with Custom setting
Let us know if this will help you
Thanks
Amit Chaudhary