If I have a hierarchical custom setting:


With one field:


Using apex, how can I surface this field in a visualforce page?

Can I just query it as if I was querying a custom object?

2 Answers 2


You can access them just like you would a custom object, using SOQL. By doing that though, you aren't fully leveraging one the big advantages of using a custom setting over a custom object, no impact on governor limits.

If you use a custom setting and access it using some of the methods provided, you are retrieving your data with zero impact on the governor limits. You aren't using any of your limited SOQL queries or counting towards the limited number of query rows you can retrieve.

Custom_Page__c cp = Custom_Page__c.getOrgDefaults();
string url = cp.url__c;

This returns you the org defaults for that custom setting, or the highest level.

You can also pass in the userID or the profileID if you have different settings based on profiles or individual users.

 Custom_Page__c cp = Custom_Page__c.getOrgDefaults(UserID or ProfileID);
 string url = cp.url__c;

Check out some of the documentation on custom setting methods here


While there is already a great answer, I would like to point out that in a VisualForce Page, you do not even need a controller at all to access this data, because you can leverage the $Setup global variable.

  • 1
    You've missed the $ character before the Setup May 25, 2016 at 16:00

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.