+ Start a Discussion
santhosh  konsanthosh kon 

Can Anybody send real time usage of custom settings? plz send the sample code?

Gaurav KheterpalGaurav Kheterpal
You can find deatils on how to access custom settings in your code here (https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_custom_settings.htm). For an example, try this

VF page
<apex:page controller="CustomSettingController">
  <apex:pageMessages id="msgs" />
  <apex:form id="theform">
    <apex:inputField value="{!cs.Field1__c}" />
    <apex:inputField value="{!cs.Field2__c}" />
    <apex:commandButton value="{!$Label.CSTab_Save}" action="{!update}" rerender="msgs,theform" />  
Apex code
 * CustomSettingController
 * @description controller class for updating custom settings...
public without sharing class CustomSettingController{
  public CustomSetting__c cs {get;set;}
  public CustomSettingController(){
    cs = CustomSetting__c.getInstance();
  public PageReference update(){
      update cs;
      ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,Label.CS_Update_Success));
    }catch(DMLException e){
      ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,Label.CS_Update_Error));
    return null;
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others and improve the overall quality of Discussion Forums.

Gaurav Kheterpal
Certified Force.com Developer| Salesforce Mobile Evangelist| Developer Forums Moderator| Dreamforce Speaker