Global Variables

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}.

$Action

Description A global merge field type to use when referencing standard Salesforce actions such as displaying the Accounts tab home page, creating new accounts, editing accounts, and deleting accounts.
Use Use dot notation to specify an object and an action, for example, $Action.Account.New
Example The following markup adds a link to create a new account:
<apex:outputLink value="{!URLFOR($Action.Account.New)}">
    Create New Account
</apex:outputLink>
The following markup adds a link to download an attachment:
<apex:page standardController="Attachment">
    <apex:outputLink value="{!URLFOR($Action.Attachment.Download,
                      attachment.id)}">
      Download Now!
    </apex:outputLink>
</apex:page>

$Api

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}
                                    

$Component

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>
Then you can refer to the component in a function like this:
document.getElementById(
    "{!$Component.theBlock.theSection.theSectionItem.text}")

$componentLabel

Description: A global merge field to use when referencing the label of an inputField component on a Visualforce page that is associated with a message.
Use: Return the label of an inputField component that is associated with a message.
Visualforce Example:
<apex:datalist var="mess" value="{!messages}">
  <apex:outputText value="{!mess.componentLabel}:" style="color:red/>
<apex:outputText value="{!mess.detail}" style="color:black" />
</apex:datalist>
Tips: This global variable is only available for Visualforce pages.

$CurrentPage

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>

$Label

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:
  1. the local translation's text
  2. the packaged translation's text
  3. the master label's text
Example
<apex:page>
   <apex:pageMessage severity="info" strength="1" summary="{!$Label.firstrun_helptext}" 
   />
</apex:page>

$Label.Site

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:
LabelMessage
authorization_requiredAuthorization Required
bandwidth_limit_exceededBandwidth Limit Exceeded
change_passwordChange Password
change_your_passwordChange Your Password
click_forget_passwordIf you have forgotten your password, click Forgot Password to reset it.
community_nicknameNickname
confirm_passwordConfirm Password
down_for_maintenance<i>{0}</i> is down for maintenance
emailEmail
email_usemail us
enter_passwordDid you forget your password? Please enter your username below.
errorError: {0}
error2Error
file_not_foundFile Not Found
forgot_passwordForgot Password
forgot_password_confirmationForgot Password Confirmation
forgot_your_password_qForgot Your Password?
get_in_touchPlease <a href="{0}">{1}</a> if you need to get in touch.
go_to_login_pageGo to Login Page
img_path/img/sites
in_maintenanceDown For Maintenance
limit_exceededLimit Exceeded
loginLogin
login_buttonLogin
login_or_register_firstYou must first log in or register before accessing this page.
logoutLogout
new_passwordNew Password
new_user_qNew User?
old_passwordOld Password
page_not_foundPage Not Found
page_not_found_detailPage Not Found: {0}
passwordPassword
passwords_dont_matchPasswords did not match.
powered_byPowered by
registerRegister
registration_confirmationRegistration Confirmation
site_loginSite Login
site_under_constructionSite Under Construction
sorry_for_inconvenienceSorry for the inconvenience.
sorry_for_inconvenience_back_shortlySorry for the inconvenience. We'll be back shortly.
stay_tunedStay tuned.
submitSubmit
temp_password_sentAn email has been sent to you with your temporary password.
thank_you_for_registeringThank you for registering. An email has been sent to you with your temporary password.
under_construction<i>{0}</i> is under construction
user_registrationNew User Registration
usernameUsername
verify_new_passwordVerify New Password
Example
<apex:page>
   <apex:pageMessage severity="info" strength="1" summary="{!$Label.Site.temp_password_sent}" 
   />
</apex:page>

$ObjectType

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}

$Organization

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}
                                    

$Page

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
<apex:page>
  <h1>Linked</h1>
  <apex:outputLink value="{!$Page.otherPage}">
    This is a link to another page.
  </apex:outputLink>
</apex:page>

$Profile

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:
  • LicenseType
  • UserType
Example
{!$Profile.Id}{!$Profile.Name}
                                    

$Resource

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"/>

$SControl

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>

$Site

Description A global merge field type to use when referencing information about the current Force.com site.
Use
Use dot notation to access information about the current Force.com site. Note that only the following site fields are available:
Merge FieldDescription
{!$Site.Name}Returns the API name of the current site.
{!$Site.Domain}Returns the Force.com domain name for your organization.
{!$Site.CustomWebAddress}Returns the value of the Custom Web Address field for the current site.
{!$Site.OriginalUrl}Returns the original URL for this page if it is a designated error page for the site; otherwise, returns null.
{!$Site.CurrentSiteUrl}Returns the value of the site URL for the current request (for example, http://myco.com/ or https://myco.force.com/prefix/).
{!$Site.LoginEnabled}Returns true if the current site is associated with an active login-enabled portal; otherwise returns false.
{!$Site.RegistrationEnabled}Returns true if the current site is associated with an active self-regitration-enabled Customer Portal; otherwise returns false.
{!$Site.IsPasswordExpired}For authenticated users, returns true if the currently logged-in user's password is expired. For non-authenticated users, returns false.
{!$Site.AdminEmailAddress}Returns the value of the Site Contact field for the current site.
{!$Site.Prefix}Returns the URL path prefix of the current site. For example, if your site URL is myco.force.com/partners, partners is the path prefix. Returns null if the prefix is not defined, or if the page was accessed using a custom Web address.
{!$Site.Template}Returns the template name associated with the current site; returns the default template if no template has been designated.
{!$Site.ErrorMessage}Returns an error message for the current page if it is a designated error page for the site and an error exists; otherwise, returns an empty string.
{!$Site.ErrorDescription}Returns the error description for the current page if it is a designated error page for the site and an error exists; otherwise, returns an empty string.
{!$Site.AnalyticsTrackingCode}The tracking code associated with your site. This code can be used by services like Google Analytics to track page request data for your site.
Example The following example shows how to use the $Site.Template merge field:
<apex:page title="Job Application Confirmation" showHeader="false" standardStylesheets="true">
<!-- The site template provides layout & style for the site --> 
    
  <apex:composition template="{!$Site.Template}">
  <apex:define name="body">
    <apex:form>
      <apex:commandLink value="<- Back to Job Search" onclick="window.top.location='{!$Page.PublicJobs}';return false;"/>
      <br/>
      <br/>
      <center><apex:outputText value="Your application has been saved. Thank 
          you for your interest!"/></center>
<br/>
      <br/>
    </apex:form>
  </apex:define>
  </apex:composition>
</apex:page>

$System.OriginDateTime

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}

$User

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>

$User.UITheme and $User.UIThemeDisplayed

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:
  • Theme1—Obsolete Salesforce theme
  • Theme2Salesforce theme used prior to Spring '10
  • PortalDefaultSalesforceCustomer Portal theme
  • WebstoreSalesforceAppExchange theme
  • Theme3—Current Salesforce theme, introduced during Spring '10
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.

$UserRole

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:
  • CaseAccessForAccountOwner
  • ContactAccessForAccountOwner
  • OpportunityAccessForAccountOwner
  • PortalType
Example
{!$UserRole.LastModifiedById}
                                    
© Copyright 2000–2012 salesforce.com, inc. All rights reserved.
Various trademarks held by their respective owners.