+ Start a Discussion
David SilvaDavid Silva 

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

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 !!!

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}"/>

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.



Best Regards,
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 


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

For more detail visit,