You can use global variables to reference general information about the current user and your organization on a Visualforce page. All global variables must be included in expression syntax, for example, {!$User.Name}.
| Description | A global merge field type to use when referencing API URLs. |
| Use | Use dot notation to specify an API URL, or to return the session ID. |
| Example |
{!$Api.Session_ID}
|
| Description | A global merge field type to use when referencing a Visualforce component. |
| Use | Each component in a Visualforce page has its own id attribute. When the page is rendered, this attribute is the same as the Document Object Model (DOM) ID.Use $Component.Id in JavaScript to reference a specific component on a page. |
| Example | The following JavaScript method references a component named
msgpost in a Visualforce page:function beforeTextSave() { document.getElementById('{!$component. msgpost}').value = myEditor.getEditorHTML(); } The page markup that follows shows the <apex:outputText> component to which msgpost refers: <apex:page> <apex:outputText id="msgpost" value="Emad is great"/> </apex:page> If your component is nested, you must
declare the entire component tree. For example, if your page looks
like this: <apex:page> <apex:pageBlock id="theBlock"> <apex:pageBlockSection id="theSection" columns="1"> <apex:pageBlockSectionItem id="theSectionItem"> <apex:outputText id="text"> Heya! </apex:outputText> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:page> document.getElementById(
"{!$Component.theBlock.theSection.theSectionItem.text}") |
| Description | A global merge field type to use when referencing the current Visualforce page. |
| Use | Use this expression in a Visualforce page to access the current page parameters and values, the current page name ($CurrentPage.Name), or the URL of the current page ($CurrentPage.URL). |
| Example |
<apex:page standardController="Account"> <apex:pageBlock title="Hello {!$User.FirstName}!"> You belong to the {!account.name} account. </apex:pageBlock> <apex:detail subject="{!account}" relatedList="false"/> <apex:relatedList list="OpenActivities" subject="{!$CurrentPage.parameters.relatedId}" /> </apex:page> |
| Description | A global merge field type to use when referencing a custom label in a Visualforce page. |
| Use | Use this expression in a Visualforce page to access
a custom label. When the application server constructs the page to
be presented to the end-user’s browser, the value returned
depends upon the language setting of the contextual user. The value
returned is one of the following, in order of precedence:
|
| Example |
<apex:page> <apex:pageMessage severity="info" strength="1" summary="{!$Label.firstrun_helptext}" /> </apex:page> |
| Description | A global merge field type to use when referencing a standard label in a Visualforce page. Like all standard labels, the text will display based on the user's language and locale. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Use | Use this expression in a Visualforce page to access
a standard label. When the application server constructs the page
to be presented to the end-user’s browser, the value returned
depends on the language and locale of the user.
Salesforce provides the following labels:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Example |
<apex:page> <apex:pageMessage severity="info" strength="1" summary="{!$Label.Site.temp_password_sent}" /> </apex:page> |
| Description | A global merge field type to use when referencing standard or custom objects such as accounts, cases, or opportunities as well as the value of a field on that object. |
| Use | Use dot notation to specify an object, such as $ObjectType.Case. Optionally, select a field on that object using the following syntax: $ObjectType.Role_Limit__c.Fields.Limit__c. |
| Example | The following example retrieves the label for the Account name
field:{!$ObjectType.Account.Fields.Name.Label}You can also use dynamic references to retrieve information about an object through $ObjectType. For example, {!$ObjectType.Account.Fields['Name'].Type} |
| Description | A global merge field type to use when referencing information about your company profile. Use organization merge fields to reference your organization's city, fax, ID, or other details. |
| Use | Use dot notation to access your organization's information.
For example:{!$Organization.Street}{!$Organization.State} The values returned for the fields are the values currently stored as part of your company information in Salesforce. Note that you cannot use the UiSkin$Organization value in Visualforce. |
| Example |
{!$Organization.Phone}
|
| Description | A global merge field type to use when referencing a Visualforce page. |
| Use | Use this expression in a Visualforce page to access another Visualforce page. |
| Example |
| Description | A global merge field type to use when referencing information about the current user's profile. Use profile merge fields to reference information about the user's profile such as license type or name. |
| Use | Use dot notation to access your organization's information. Note that you cannot use the following $Profile values in Visualforce:
|
| Example |
{!$Profile.Id}{!$Profile.Name} |
| Description | A global merge field type to use when referencing an existing static resource by name in a Visualforce page. You can also use resource merge fields in URLFOR functions to reference a particular file in a static resource archive. |
| Use | Use $Resource to reference an existing static resource. The format is $Resource.nameOfResource, such as $Resource.TestImage. |
| Examples | The Visualforce component below references an image file that was uploaded as a
static resource and given the name TestImage:
<apex:image url="{!$Resource.TestImage}" width="50" height="50"/> To reference a file in an archive (such as a .zip or .jar file), use the URLFOR function. Specify the static resource name that you provided when you uploaded the archive with the first parameter, and the path to the desired file within the archive with the second. For example: <apex:image url="{!URLFOR($Resource.TestZip, 'images/Bluehills.jpg')}" width="50" height="50"/> |
| Description | A global merge field type to use when referencing an existing custom s-control by name. This merge field type results in a URL to a page where the s-control executes. |
| Use | Use dot notation to access an existing s-control by its name. |
| Examples | The following example shows how to link to an s-control named
HelloWorld in a Visualforce page:<apex:page> <apex:outputLink value="{!$SControl.HelloWorld}">Open the HelloWorld s-control</apex:outputLink> </apex:page> Note that if you simply want to embed an s-control in a page, you can use the <apex:scontrol> tag without the $SControl merge field. For example: <apex:page> <apex:scontrol controlName="HelloWorld" /> </apex:page> |
| Description | A global merge field that represents the literal value of 1900-01-01 00:00:00. |
| Use | Use this global variable when performing date/time offset calculations or to assign a literal value to a data/time field. |
| Example | The following example calculates the number of days that have
passed since 1900:{!NOW() - $System.OriginDateTime} |
| Description | A global merge field type to use when referencing information about the current user. User merge fields can reference information about the user such as alias, title, and ID. |
| Use | Use dot notation to access the current user's information.
For example:{!IF (CONTAINS($User.Alias, Smith) True, False)} |
| Example | The following example displays the current user's company name,
as well as the status of the current user (which returns a Boolean
value.) <apex:page> <h1>Congratulations</h1> This is your new Page <p>The current company name for this user is: {!$User.CompanyName}</p> </apex:page> |
| Description | These global merge fields identify
the Salesforce look
and feel a user sees on a given Web page.
The difference between the two variables is that $User.UITheme returns the look and feel set by the user, while $User.UIThemeDisplayed returns the actual look and feel. For example, a user may have the permissions to see the new user interface theme look and feel, but if they are using a browser that doesn't support that look and feel, $User.UIThemeDisplayed returns a different value. Factors that affect the expected theme from displaying include the user agent of the browser and whether accessibility mode is enabled. |
| Use | Use these variables to identify the CSS
used to render Salesforce web pages to a user. Both variables return one of the following
values:
|
| Example | The following example shows how you can
render different layouts based on a user's theme:
<apex:page> <apex:pageBlock title="My Content" rendered="{!$User.UITheme == 'Theme2'}"> // this is the old theme... </apex:pageBlock> <apex:pageBlock title="My Content" rendered="{!$User.UITheme == 'Aloha'}"> //this is the new theme ... </apex:pageBlock> </apex:page> The section “Styling Visualforce Pages” in the Visualforce Developer's Guide provides more information on how to use these global variables. |
| Description | A global merge field type to use when referencing information about the current user's role. Role merge fields can reference information such as role name, description, and ID. |
| Use | Use dot notation to access information about the current user’s
role. Note that you cannot use the following $UserRole values in Visualforce:
|
| Example |
{!$UserRole.LastModifiedById}
|