INTRODUCTION TO FORCE.COM PROGRAMMING 2
Let's assign a tab to the page you created in step #1. This way when you make changes you can see them easily. You can always view your page by entering the url as in step one like this:
https://c.na6.visual.force.com/apex/helloworld, where everything before /apex/helloworls is your particular org.
Assign tab:Click through [Setup | (App Setup) Create | Tabs | Visualforce Tabs | New]. Name the tab Hello World and select a color & icon for it.
The code generated for Visualforce looks like this:
<apex:page >
<!-- Begin Default Content REMOVE THIS -->
<h1>Congratulations</h1>
This is your new Page: helloworld
<!-- End Default Content REMOVE THIS -->
</apex:page>
After we create the Apex controller class to handle a button click, we will change the above code to bind the button and display the results.
Create Apex class:Click through [Setup | Develop | Apex Classes | New]
Paste the following code into the editor:
public class HelloWorld
{
public String displayText {get; set;}
public void SayIt()
{
displayText = 'Hello World!!';
}
}
Save the class and return to your Visualforce page: [Setup | Develop | Pages | helloworld | Edit]
Change the Visualforce code to the following:<apex:page controller="HelloWorld">
<apex:sectionHeader title="Some Title" subtitle="Some Subtitle"/>
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons location="bottom">
<apex:commandButton action="{!SayIt}" value="Hello who?"/>
</apex:pageBlockButtons>
<apex:outputLabel value="Results: " for="results"/>
<apex:inputTextarea id="results" value="{!displayText}" rows="10" style="width: 100%"/>
</apex:pageBlock>
</apex:form>
</apex:page>
Now click on your Hello World tab to see the results. With a button we've gone from Visualforce to Apex and now have the entire database along with all the other tools at our fingertips.