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?
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.Sign up to join this community
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.