Create a new Visualforce page, accountDisplay, with the following content:
You’ll recognize the {! } expression syntax from the previous tutorial, and that $User.FirstName refers to the First Name field of the User global variable. There are a few new things though:
<apex:page standardController="Account"> <p>Hello {! $User.FirstName}!</p> <p>You are viewing the {! account.name} account.</p> </apex:page>
- The standardController="Account" attribute tells Visualforce to use an automatically-generated controller for the Account object, and to provide access to the controller in theVisualforce page.
- The {! account.name} expression retrieves the value of the account variable’s name field. The account variable is automatically made available by the standard controller (it’s named after the standard controller’s name).
Controllers generally have logic that handles button clicks and interacts with the database. By using the standardController attribute, your Visualforce page has access to a rich controller that is automatically generated for you.
The standard controller for the Account object determines when an identifier is being used in the page, and if it is, queries the database and retrieves the record associated with that identifier. It then assigns that record to the account variable so that you can do as you please with the data in your Visualforce page.
When you click Save, you will see your first name and an empty account name. This is because you haven’t told the Visualforce page which account record to display. Go to your URL and modify it so that you include the ID from Step 1. So instead of something like:
change it to something like:
In your case, change the identifier 0018000000MDfn1 to whatever you found in Step 1. You might need to change “na3” as well, to whatever your salesforce instance currently is.
https://na3.salesforce.com/apex/accountDisplay
https://na3.salesforce.com/apex/accountDisplay?id=0018000000MDfn1
Now when you save your work, the account name displays:
No comments:
Post a Comment