function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
David SilvaDavid Silva 

How to get the custom setting values in the apex code.

Hi,
How to get the custom setting values in the apex code.
Naresh YadavNaresh Yadav
Hi David Silva,

You can query them like custom objects.

Ex.  Suppose you have a custom setting named as 'Custom_Setting__c' .

So if you want it in your class then query it like [SELCT id, Name FROM Custom_Setting__c].
Amritesh SahuAmritesh Sahu
Hi David,

You can get custom setting value without using SOQL, 
Suppose you have custom setting Games__c.

You can get the list of records through :
List<Games__c> mcs = Games__c.getall().values();

To get individual record 'My Games' of custom setting :
Games__c objGame = Games__c.getValues('My Games');

Hope it helps !!!

Regards,
Amritesh
JyothsnaJyothsna (Salesforce Developers) 
Hi David,

For example, you have a custom setting for Country Code. It has 2 fields:
Name (object Name field same as when you create a custom object)
Code (Text field).

Visualforce Page
 
<apex:page controller="sample" sidebar="false" >
<apex:form >
    <apex:pageblock >
        <apex:pageblockTable value="{!code}" var="c">
            <apex:column value="{!c.Name}"/>        
            <apex:column value="{!c.Code__c}"/>
        </apex:pageblockTable>
    </apex:pageblock>
</apex:form>
</apex:page>

Controller
 
public class sample
{
    public List<CountryCodes__c> code {get;set;}
   
    public sample()
    {
        Map<String,CountryCodes__c> allCodes = CountryCodes__c.getAll();
        code = allCodes.values();
    }  
   
}

Please check the below links for more examples of custom settings.

http://blogatsalesforce.blogspot.sg/2015/03/use-custom-setting-efficiently-in-apex.html


https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_custom_settings.htm

Best Regards,
Jyothsna
 
farukh sk hdfarukh sk hd
Let say we have custom setting called employee where we are storing employee roll number. 
Let's assume we have some employee information stored in custom setting. 
employee1     rollNo1 
employee2    rollNo2 

Syntax: 

Employee__c obj=new Employee__c.getvalues('employee1'); 
String rolNo=obj.rollNo1__c; 

For more detail visit,

https://www.sfdc-lightning.com/2018/09/custom-settings-in-salesforce.html