2

I'm trying to show the value of a custom setting in a Visualforce page using custom controller

Put the controller

public Client__c phone {get;set;} 
  public static Client__c phone =  Client__c.getOrgDefaults();

And Visualforce Page

Phone: {!phone}

But it shows the value of the page

Can anyone help?

1
  • getorgDefaults will get you default values but if you are looking for specific data from a custom settings please refer the answer below – Mohith Shrivastava Aug 9 '13 at 11:33
3

At the visualforce page you need to define witch setting you want to show. With getOrgDefaults() method you will get the custom setting data set record for the organization. In this set all the settings are saved. You need to provide the setting API name:

Phone: {!phone.SettingName__c}

You can learn more about it here: Custom Settings Methods, Accessing Custom Settings

2

If its hierarchical custom setting you can access in visualforce using global variables

{!$Setup.Client_c.Field__c} 

Where Field__c is the field from the custom setting you want to access data

Here is the sample page and class that you can refer to get started

<apex:page controller="customsettingcontroller">

 <div>
 -----------Accessing Hirerachy Custom Setting No Need Of controller------------------------------

</div>

 <div>

   {!$Setup.Client__c.Phone__c} 
 </div>

 <div>
  -----------------------------------------Accessing List Custom Setting requires some code in controller-----------------------

 </div>
   <div>
   {!phone}

   </div>

 </apex:page>

Controller class

public class customsettingcontroller{

public String getphone(){

    return Clientlist__c.getInstance('Client').phone__c;

}

}
3
  • Thanks. can I put on the visuaforce page? rendered="{!$Setup.Client_c.Field__c} !=null" /> – user3513 Aug 9 '13 at 13:34
  • @user3513 Put: rendered="{!$Setup.Client_c.Field__c !=null}" – Sergej Utko Aug 9 '13 at 13:39
  • @user3513 If the explanation solves your problem then please dont forget to mark as answer either mine or mast0r.If you have better solution please post and mark the answer as true . – Mohith Shrivastava Aug 9 '13 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.