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
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:form>
</apex:page>
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(){
    try{
      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));
      System.debug(e);
    }
    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