Force.com retains information about the logged-in user in a variable called User. You can access fields of this User variable (and any others) by using a special expression language syntax: {! $<global variable>.<field name>}
- Modify your existing page to include the following line: {! $User.FirstName}. Remember that any content must lie within the <apex:page> component (between its open and closing tags).
- Click Save.
Your Visualforce page looks something like this:
<apex:page sidebar="false"> {! $User.FirstName} </apex:page>
In the future we’ll assume that you know to put any Visualforce markup within the <apex:page> tag. We’ll also assume that by now you’re comfortable enough to “Click Save” and view the result as well!
The {! ... } tells Visualforce that whatever lies within the braces is dynamic and written in the expression language, and its value must be calculated and substituted at run time when someone views the page. Visualforce is case-insensitive, and spaces within the {! ... } syntax are also ignored. So this is just as effective:{!$USER.firstname}.
Here’s how to show the first name and last name of the logged-in user: {! $User.FirstName} {! $User.LastName}
No comments:
Post a Comment