As a beginner I face difficulties in SalesForce even when with simple problems like fetching data and displaying them on the VisualForce page. Now that I have some knowlede on it, I would like to share it.
Let’s begin with how to fetch and display data from a custom object on VisualForce page.
Code
VisualForce Page
Congratulations
This is your new Page : Hello World ...!
Apex Controller
global with sharing class poistionController { public Position__c pos{get;set;} public poistionController() { pos = [select Max_Pay__c from Position__c where Name = 'Sr. Java Developer']; } }
In the apex controller positionController, we made a reference of the custom object Position__c
Since Position is a custom object, it has a suffix ‘__c’.
In the next line, we defined a constructor which fetches the value to be shown in the VisualForce Page.
The controller for the VisualForce page is positionController which is a class defined with same name as positionController.
ShowHeader is made false so that the default header of salesforce.com will not be displayed.
Now, our aim is to display the value in the VisualForce Page.
Please look at the below mentioned line of code.
Here, we are displaying the value of Max_Pay__c field of Position custom object.