Loading
Salesforce now sends email only from verified domains. Read More
Enhance Salesforce with Code
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          . Global Variables

          Global Variables

          When you work with components such as custom buttons and links, formulas in custom fields, validation rules, flows, processes, and Visualforce pages, you can use special merge fields to reference data in Salesforce.

          Required Editions

          The availability of each global variable depends on the experience and edition requirements for the related feature.
          User Permissions Needed
          To create, edit, and delete custom s-controls, formulas, or Visualforce pages: Customize Application
          To edit flows and processes: Manage Flow
          Note
          Note Web tabs support only $User, $Organization, and $Api merge fields.

          Use these global variables when choosing a merge field type to add to your custom component:

          $Action

          Description: A global merge field type to use when referencing standard Salesforce actions, such as displaying the Accounts tab home page, creating accounts, editing accounts, and deleting accounts. Use action merge fields in LINKTO and URLFOR functions to reference the action selected.
          Use:
          • Select the field type: $Action.
          • Insert a merge field in the format $Action.object.action, such as $Action.Account.New.
          S-Control Example:

          This s-control references the standard action for creating accounts in the $Action.Account.New merge field.

          <html>
              <body>
                  {!LINKTO(
                      "Create a New Account", 
                      $Action.Account.New, 
                      $ObjectType.Account
                   )}
              </body>
          </html>
          Visualforce Example:
          <apex:outputLink value="{!URLFOR($Action.Account.New)}">
              Create New Account
          </apex:outputLink>
          Tips: This global variable is only available for custom buttons and links, s-controls, and Visualforce pages.

          All objects support basic actions, such as new, clone, view, edit, list, and delete. The $Action global also references actions available on many standard objects. The values available in your organization can differ depending on the features you enable.

          $Api

          Description: A global merge field type to use when referencing API URLs.  
          Use:
          • Select the field type: $Api.
          • Select a merge field, such as:
            • $Api.Enterprise_Server_URL__xxx: The Enterprise WSDL SOAP endpoint where xxx represents the version of the API. For example, $Api.Enterprise_Server_URL_140 is the merge field value for version 14.0 of the API.
            • $Api.Partner_Server_URL__xxx: The Partner WSDL SOAP endpoint where xxx represents the version of the API.
            • $Api.Session_ID: The session ID.
           
          S-Control Example:

          This custom formula field calls a service to replace the SIC code. Replace myserver with the name of your server.

          HYPERLINK("https://www.myserver.com/mypage.jsp" & 
          "?Username="       & $User.Username & 
          "&crmSessionId="   & GETSESSIONID() & 
          "&crmServerUrl="   &  $Api.Partner_Server_URL_90  &
          "&crmObjectId="    & Id &
          "&crmFieldUpdate=sicCode",
          "Update SIC Code")
           
          Visualforce and Flow Example:

          Use dot notation to return the session ID.

          {!$Api.Session_ID}
           
          Tips:

          This global variable is only available for formula fields, s-controls, custom buttons and links, Visualforce pages, flows, and process formulas.

          $Api.Session_ID and GETSESSIONID() return the same value, an identifier for the current session in the current context. This context varies depending on where the global variable or function is evaluated. For example, if you use either in a custom formula field and that field is displayed on a standard page layout in Salesforce Classic, the referenced session is a basic Salesforce session. That same field (or the underlying variable or formula result), when used in a Visualforce page, references a Visualforce session instead.

          Session contexts are based on the domain of the request. That is, the session context changes whenever you cross a hostname boundary, such as from .salesforce.com to .vf.force.com or .lightning.force.com.

          Session identifiers from different contexts, and the sessions themselves, are different. When you transition between contexts, the old session is replaced by the new one, and the old session is no longer valid. The session ID also changes at this time.

          Normally Salesforce transparently handles session hand-off between contexts, but if you’re passing the session ID around yourself, you might need to re-access $Api.Session_ID or GETSESSIONID() from the new context to ensure a valid session ID.

          Not all sessions are created equal. In particular, sessions obtained in a Lightning Experience context have reduced privileges and don't have API access. You can't use these session IDs to make API calls. {!$Api.Session_ID} isn’t generated for guest users.

           

          $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 used to generate the Document Object Model (DOM) ID. Use $Component.Path.to.Id in JavaScript to reference a specific component on a page, where Path.to.Id is a component hierarchy specifier for the component being referenced.
          Visualforce Example:
          function beforeTextSave() {
              document.getElementById('{!$Component.msgpost}').value = myEditor.getEditorHTML();
          }
          
          Tips: This global variable is only available for Visualforce pages.

          $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 or page request.
          Use: Use this global variable in a Visualforce page to reference the current page name ($CurrentPage.Name) or the URL of the current page ($CurrentPage.URL). Use $CurrentPage.parameters.parameterName to reference page-request parameters and values, where parameterName is the request parameter being referenced. parameterName isn't case-sensitive.
          Visualforce Example:
          <apex:page standardController="Account">
              <apex:pageBlock title="Hello {!$User.FirstName}!">
                  You belong to the {!account.name} account.<br/>
                  You're also a nice person.
              </apex:pageBlock>
              <apex:detail subject="{!account}" relatedList="false"/>
              <apex:relatedList list="OpenActivities" 
                  subject="{!$CurrentPage.parameters.relatedId}"/> 
          </apex:page>
          Tips: This global variable is only available for Visualforce pages.

          $CustomMetadata

          Description: A custom metadata record. Available in API version 43.0 and later.
          Use: Use this global variable in validation rule formulas to dynamically reference custom metadata types using the syntax $CustomMetadata.type.record.field.
          Tips: This global variable only supports validation rule formulas.

          $FieldSet

          Description: Provides access to a field set defined in your organization.
          Use: Use this in your Visualforce pages to dynamically iterate over fields in a field set. You must prefix this global variable with a reference to the standard or custom object that has the field set.
          Visualforce Example:
          <apex:page standardController="Account">
              <apex:repeat value="{!$ObjectType.Account.FieldSets.myFieldSetName}" var="field">
                  <apex:outputText value="{!field}" />
              </apex:repeat>
          </apex:page>
          Tips: This global variable is only available for Visualforce pages.

          $Label

          Description: A global merge field type to use when referencing a custom label.
          Use:
          • Select the field type $Label.
          • Select the custom label that you want to reference.

          The returned value depends on the language setting of the contextual user.​ The value returned is one of these, in order of precedence:

          • The local translation’s text
          • The packaged translation’s text
          • The primary label’s text
          Flow Example:

          Create a flow formula whose expression is:

          {!$Label.customCurrency_label}

          Then reference that flow formula as the label of a screen component.

          Visualforce Example:
          <apex:page>
              <apex:pageMessage severity="info" 
                  strength="1" 
                  summary="{!$Label.firstrun_helptext}" 
              />
          </apex:page>
          Aura Components Example
          Label in a markup expression using the default namespace
          {!$Label.c.labelName}
          Label expressions in markup are supported in .cmp and .app resources only.
          Label in JavaScript code if your org has a namespace
          $A.get("$Label.namespace.labelName")
          Tips: This global variable is available for Aura components, Visualforce pages, Apex, flows, and process formulas only.

          $Label.Site

          Description: A global merge field type used to reference a standard Sites label in a Visualforce page. As with all standard labels, the label’s message displays according to the user’s language and locale. You can’t modify the message of a standard Sites label. To use a custom message, create a custom label, and then reference the label with the $Label global variable.
          Use: Use this expression in a Visualforce page to access a standard Sites 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.
          Visualforce Example:
          <apex:page>
              <apex:pageMessage severity="info" 
                  strength="1" 
                  summary="{!$Label.Site.temp_password_sent}" 
              />
          </apex:page>
          Tips: This global variable is only available for Visualforce pages.

          Salesforce provides these labels:

          Label Message
          authorization_required Authorization Required
          bandwidth_limit_exceeded Bandwidth Limit Exceeded
          change_password Change Password
          change_your_password Change Your Password
          click_forget_password If you have forgotten your password, click Forgot Password to reset it.
          community_nickname Nickname
          confirm_password Confirm Password
          down_for_maintenance <i>{0}</i> is down for maintenance
          email Email
          email_us email us
          enter_password Did you forget your password? Please enter your username below.
          error Error: {0}
          error2 Error
          file_not_found File Not Found
          forgot_password Forgot Password
          forgot_password_confirmation Forgot Password Confirmation
          forgot_your_password_q Forgot Your Password?
          get_in_touch Please <a href="{0}">{1}</a> if you need to get in touch.
          go_to_login_page Go to Login Page
          img_path /img/sites
          in_maintenance Down For Maintenance
          limit_exceeded Limit Exceeded
          login Login
          login_button Login
          login_or_register_first You must first log in or register before accessing this page.
          logout Logout
          new_password New Password
          new_user_q New User?
          old_password Old Password
          page_not_found Page Not Found
          page_not_found_detail Page Not Found: {0}
          password Password
          passwords_dont_match Passwords did not match.
          powered_by Powered by
          register Register
          registration_confirmation Registration Confirmation
          site_login Site Login
          site_under_construction Site Under Construction
          sorry_for_inconvenience Sorry for the inconvenience.
          sorry_for_inconvenience_back_shortly Sorry for the inconvenience. We'll be back shortly.
          stay_tuned Stay tuned.
          submit Submit
          temp_password_sent An email has been sent to you with your temporary password.
          thank_you_for_registering Thank you for registering. An email has been sent to you with your temporary password.
          under_construction <i>{0}</i> is under construction
          user_registration New User Registration
          username Username
          verify_new_password Verify New Password

          $Network

          Description: A global merge field type to use when referencing Experience Cloud site details in a Visualforce email template.
          Use: Use this expression in a Visualforce email template to access the Experience Cloud site name and login URL.
          Visualforce Example:
          <messaging:emailTemplate subject="Your Password has been reset" recipientType="User">
              <messaging:htmlEmailBody >
                  <p>Hi,</p>
                  <p>Your password for <b>{!$Network.Name}</b> has been reset.</p>
                  <p><a href='{!$Network.NetworkUrlForUserEmails}'>Reset Password</a></p>
                  <p>Regards,</p>
                  <p>Community Manager</p>
              </messaging:htmlEmailBody>
          </messaging:emailTemplate>
          Tips: This global variable works only in Visualforce email templates for Experience Cloud sites.

          $MessageChannel

          Description: A global merge field type to provide access to a message channel defined in your organization.
          Use: Use this expression in your Visualforce page to access a message channel and use the Lightning Message Service APIs.
          Visualforce Example:
          <apex:page>
              <script>
                  // Load the MessageChannel token in a variable
                  var SAMPLEMC = "{!$MessageChannel.SampleMessageChannel__c}";
                  function handleClick() {
                      const payload = {
                          recordId: "some string",
                          recordData: {value: "some value"}
                      }
                      sforce.one.publish(SAMPLEMC, payload);
                  }
              </script>
              <div>
                  <p>Publish SampleMessageChannel</p>
                  <button onclick="handleClick()">Publish</button>
              </div>
          </apex:page>
          Tips: This global variable is available for Visualforce pages.

          $ObjectType

          Description: A global merge field type to use when referencing standard or custom objects (such as Accounts, Cases, or Opportunities) and the values of their fields. Use object type merge fields in LINKTO, GETRECORDIDS, and URLFOR functions to reference a specific type of data or the VLOOKUP function to reference a specific field in a related object.
          Use:
          • Select the field type: $ObjectType.
          • Select an object to insert a merge field representing that object, such as $ObjectType.Case.

            Optionally, select a field on that object using this syntax: $ObjectType.Role_Limit__c.Fields.Limit__c.

          Custom Button Example:

          This custom list button references the cases standard object in the $ObjectType.Case merge field.

          {!REQUIRESCRIPT ("/soap/ajax/13.0/connection.js")}
          var records = {!GETRECORDIDS($ObjectType.Sample)};
          var newRecords = [];
          if (records[0] == null) {
              alert("Please select at least one row")
          } else {
              for (var n=0; n<records.length; n++) {
                  var c = new sforce.SObject("Case");
                  c.id = records[n];
                  c.Status = "New";
                  newRecords.push(c);
              }
              result = sforce.connection.update(newRecords);
              window.location.reload();
          }
          Validation Rule Example:

          This example checks that a billing postal code is valid by looking up the first five characters of the value in a custom object called Zip_Code__c that contains a record for every valid zip code in the US. If the zip code isn’t found in the Zip_Code__c object or the billing state doesn’t match the corresponding State_Code__c in the Zip_Code__c object, an error is displayed.

          AND(
              LEN(BillingPostalCode) > 0, 
              OR(BillingCountry = "USA", BillingCountry = "US"), 
              VLOOKUP(
                  $ObjectType.Zip_Code__c.Fields.State_Code__c,
                  $ObjectType.Zip_Code__c.Fields.Name,
                  LEFT(BillingPostalCode,5)
              ) <> BillingState
          )
          Visualforce Example:

          This example retrieves the label for the Account Name field:

          {!$ObjectType.Account.Fields.Name.Label}
          Tips: This global variable is available in Visualforce pages, custom buttons and links, s-controls, and validation rules.

          $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:
          • Select the field type: $Organization.
          • Select a merge field such as $Organization.Fax.
          Validation Rule Example:

          Use organization merge fields to compare any attribute for your organization with that of your accounts. For example, you may want to determine if your organization has the same country as your accounts. This validation formula references your organization’s country merge field and requires a country code for any account that’s foreign.

          AND($Organization.Country <> BillingCountry, ISBLANK(Country_Code__c))
          Flow Example: Create a flow formula (Text) whose expression is {!$Organization.City}. In a Decision element, check whether a contact’s city matches that formula.
          Visualforce Example:

          Use dot notation to access your organization’s information. For example:

          {!$Organization.Street}
          {!$Organization.State}
          Tips:

          The organization merge fields get their values from whatever values are currently stored as part of your company information in Salesforce.

          Note that {!$Organization.UiSkin} is a picklist value, so use it with picklist functions such as ISPICKVAL() in custom fields, validation rules, Visualforce expressions, flow formulas, process formulas, and workflow rule formulas.

          $Page

          Description: A global merge field type to use when referencing a Visualforce page.
          Use: Use this expression in a Visualforce page to link to another Visualforce page.
          Visualforce Example:
          <apex:page>
              <h1>Linked</h1>
              <apex:outputLink value="{!$Page.otherPage}">
                  This is a link to another page.
              </apex:outputLink>
          </apex:page>
          Tips: This global variable is only available for Visualforce pages.

          $Permission

          Description: A global merge field type to use when referencing information about the current user’s custom permission access. Use permission merge fields to reference information about the user’s current access to any of your organization’s custom permissions.
          Use:
          • Select the field type: $Permission.
          • Select a merge field such as $Permission.customPermissionName.
          Validation Rule Example:

          This validation rule references the custom permission changeAustinAccounts for the current user. This rule ensures that only users with changeAustinAccounts can update accounts with a billing city of Austin.

          BillingCity = 'Austin' && $Permission.changeAustinAccounts
          Flow Example:

          This flow formula evaluates whether the current user has the deleteCandidates custom permission.

          {!$Permission.deleteCandidates}
          Visualforce Example:

          To have a pageblock appear only for users that have the custom permission seeExecutiveData, use this:

          <apex:pageBlock rendered="{!$Permission.canSeeExecutiveData}">
              <!-- Executive Data Here -->
          </apex:pageBlock>
          Tips: $Permission appears only when custom permissions have been created in your organization. This global variable isn’t supported for processes, flows, and workflow rules.

          $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:
          • Select the field type: $Profile.
          • Select a merge field such as $Profile.Name.
          Validation Rule Example:

          This validation rule formula references the profile name of the current user to ensure that only the record owner or users with this profile can make changes to a custom field called Personal Goal:

          AND(
              ISCHANGED( Personal_Goal__c ), 
              Owner <> $User.Id, 
              $Profile.Name <> "Custom: System Admin" 
          )
          Flow Example:

          Create a flow formula (Text) with this expression.

          {!$Profile.Name}

          By referencing that formula, you avoid using a query (Lookup elements) and save on limits.

          Visualforce Example:

          To return the current user's profile, use this:

          {!$Profile.Name}
          Tips:
          • $Profile merge fields are only available in editions that can create custom profiles.
          • Use profile names to reference standard profiles in $Profile merge fields.

          • Your merge field values are blank when the profile attributes are blank. For example, profile Description isn’t required and sometimes doesn’t contain a value.
          • You don’t need to give users permissions or access rights to their profile information to use these merge fields.

          If you previously referenced the internal value for a profile, use this list to determine the name to use instead:

          Standard Profile Name $Profile Value
          System Administrator PT1
          Standard User PT2
          Ready Only PT3
          Solution Manager PT4
          Marketing User PT5
          Contract Manager PT6
          Partner User PT7
          Standard Platform User PT8
          Standard Platform One App User PT9
          Customer Portal User PT13
          Customer Portal Manager PT14

          $RecordType

          Description: A global merge field to use when referencing the record type of the current record.
          Use: Add $RecordType manually to your s-control.
          Visualforce Example:

          To return the ID of the current record type, use this:

          {$RecordType.Id}
          Tips:
          • Use $RecordType.Id instead of $RecordType.Name to reference a specific record type. While $RecordType.Name makes a formula more readable, you must update the formula if the name of the record type changes, whereas the ID of a record type never changes. However, when you are deploying formulas across organizations (for example, between sandbox and production), use $RecordType.Name because IDs aren’t the same across organizations.
          • Avoid using $RecordType in formulas, except in default value formulas. Instead, use the RecordType merge field (for example, Account.RecordType.Name) or the RecordTypeId field on the object.
          • Don’t reference any field with the $RecordType merge field in cross-object formulas. The $RecordType variable resolves to the record containing the formula, not the record to which the formula spans. Use the RecordType merge field on the object instead.

          $Request

          Description: A global merge field to use when referencing a query parameter by name that returns a value.
          Use: Add $Request manually to your s-control.
          S-Control Example:

          This snippet, named Title_Snippet, requires two input parameters: titleTheme and titleText. You can reuse it in many s-controls to provide page title and theme in your HTML.

          <h2 class="{!$Request.titleTheme}.title">
              {!$Request.titleText}
          </h2>

          This s-control calls this snippet using the INCLUDE function, sending it the parameters for both the title and theme of the HTML page it creates.

          <html>
              <head/>
              <body> 
                  {!INCLUDE(
                          $SControl.Title_Snippet, 
                          [titleTheme = "modern", titleText = "My Sample Title"]
                  )}
                  Insert your page-specific content here ... 
              </body> 
          </html>
          Tips: Don’t use $Request in Visualforce pages to reference query parameters. Use $CurrentPage instead.

          $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.
          Visualforce Examples:

          This Visualforce component 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"/>
          Tips: This global variable is only available for Visualforce pages.

          $SControl

          Important
          Important Visualforce pages supersede s-controls. Organizations that haven't previously used s-controls can’t create them. Existing s-controls are unaffected and can still be edited.
          Description: A global merge field type to use when referencing an existing custom s-control by name. Use s-control merge fields in LINKTO, INCLUDE, and URLFOR functions to reference one of your custom s-controls.
          Use:
          • Select the field type: $SControl.
          • Select an s-control to insert a merge field representing that s-control, such as $Scontrol.Header_Snippet.
          S-Control Example:

          This s-control references the snippet in the $Scontrol.Header_Snippet merge field:

          <html>
              <body>
                  {!INCLUDE(
                      $SControl.Header_Snippet, 
                      [title = "My Title", theme = "modern"]
                   )}
              </body>
          </html>
          Visualforce Example:

          This 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 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>
          Tips:
          • The drop-down list for Insert Merge Field lists all your custom s-controls except snippets. Although snippets are s-controls, they behave differently. For example, you can’t reference a snippet from a URLFOR function directly; snippets aren’t available when creating a custom button or link that has a Content Source of Custom S-Control; and you can’t add snippets to your page layouts. To insert a snippet in your s-control, use the Insert Snippet drop-down button.
          • This global variable is only available for custom buttons and links, s-controls, and Visualforce pages.

          $Setup

          Description: A global merge field type to use when referencing a custom setting of type “hierarchy.”
          Use:

          Use $Setup to access hierarchical custom settings and their field values using dot notation. For example, $Setup.App_Prefs__c.Show_Help_Content__c.

          Hierarchical custom settings allow values at any of three different levels:

          • Organization, the default value for everyone
          • Profile, which overrides the Organization value
          • User, which overrides both Organization and Profile values

          Salesforce automatically determines the correct value for this custom setting field based on the running user’s current context.

          Formula Field Example:
          {!$Setup.CustomSettingName__c.CustomFieldName__c}

          Formula fields only work for hierarchy custom settings; they can’t be used for list custom settings.

          Visualforce Example:

          This example illustrates how to conditionally display an extended help message for an input field, depending on the user’s preference:

          <apex:page>
              <apex:inputField value="{!usr.Workstation_Height__c}"/>
              <apex:outputPanel id="helpWorkstationHeight" 
                  rendered="{!$Setup.App_Prefs__c.Show_Help_Content__c}">
                  Enter the height for your workstation in inches, measured from the 
                  floor to top of the work surface.
              </apex:outputPanel>
              ...
          </apex:page>
          

          If the organization level for the custom setting is set to true, users see the extended help message by default. If an individual prefers to not see the help messages, they can set their custom setting to false to override the organization (or profile) value.

          Custom settings of type “list” aren’t available on Visualforce pages using this global variable. You can access list custom settings in Apex.

          Tips: This global variable is available in Visualforce pages, formula fields, validation rules, flows, and process formulas.

          $Site

          Description: A global merge field type to use when referencing information about the current Salesforce site.
          Use:

          Use dot notation to access information about the current Salesforce site.

          Visualforce Example:

          This 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>
          Tips: This global variable is available in Visualforce pages, email templates, and s-controls.

          Note that only these site fields are available:

          Merge Field Description
          $Site.Name Returns the API name of the current site.
          $Site.Domain Returns your Salesforce Sites based URL.
          $Site.CustomWebAddress Returns the request's custom URL if it doesn't end in force.com or returns the site's primary custom URL. If neither exist, then this returns an empty string. Note that the URL's path is always the root, even if the request's custom URL has a path prefix. If the current request isn't a site request, then this field returns an empty string. This field's value always ends with a / character. Use of $Site.CustomWebAddress is discouraged, and we recommend using $Site.BaseCustomUrl instead.
          $Site.OriginalUrl Returns the original URL for this page if it’s a designated error page for the site; otherwise, returns null.
          $Site.CurrentSiteUrl Returns the base URL of the current site that references and links should use. Note that this field might return the referring page's URL instead of the current request's URL. This field's value includes a path prefix and always ends with a / character. If the current request isn't a site request, then this field returns an empty string. Use of $Site.CurrentSiteUrl is discouraged. Use $Site.BaseUrl instead.
          $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-registration-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 an empty string. This merge field is deprecated.
          $Site.Prefix Returns the URL path prefix of the current site. For example, if your site URL is MyDomainName.my.salesforce-sites.com/partners, /partners is the path prefix. Returns null if the prefix isn’t defined. If the current request isn't a site request, then this field returns an empty string.
          $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’s 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’s 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. Services such as Google Analytics can use this code to track page request data for your site.
          $Site.BaseCustomUrl

          Returns a base URL for the current site that doesn’t use a subdomain. The returned URL uses the same protocol (HTTP or HTTPS) as the current request if at least one non-force.com custom URL that supports HTTPS exists on the site. The returned value never ends with a / character. If all the custom URLs in this site end in force.com or salesforce-sites.com, or if this site has no custom URL’s, then this returns an empty string. If the current request isn't a site request, then this method returns an empty string.

          This field replaces CustomWebAddress and includes the custom URL's path prefix.

          $Site.BaseInsecureUrl This merge field is deprecated. Returns a base URL for the current site that uses HTTP instead of HTTPS. The current request's domain is used. The returned value includes the path prefix and never ends with a / character. If the current request isn't a site request, then this method returns an empty string
          $Site.BaseRequestUrl Returns the base URL of the current site for the requested URL. This isn't influenced by the referring page's URL. The returned URL uses the same protocol (HTTP or HTTPS) as the current request. The returned value includes the path prefix and never ends with a / character. If the current request isn't a site request, then this method returns an empty string.
          $Site.BaseSecureUrl Returns a base URL for the current site that uses HTTPS instead of HTTP. The current request's domain is preferred if it supports HTTPS. Domains that aren’t force.com subdomains are preferred over force.com subdomains. A force.com subdomain, if associated with the site, is used when no other HTTPS domains exist in the current site. If there are no HTTPS custom URLs in the site, then this method returns an empty string. The returned value includes the path prefix and never ends with a / character. If the current request isn't a site request, then this method returns an empty string.
          $Site.BaseUrl

          Returns the base URL of the current site that references and links should use. Note that this field may return the referring page's URL instead of the current request's URL. This field's value includes the path prefix and never ends with a / character. If the current request isn't a site request, then this field returns an empty string.

          This field replaces $Site.CurrentSiteUrl.

          $Site.MasterLabel Returns the value of the Master Label field for the current site. If the current request isn't a site request, then this field returns an empty string.
          $Site.SiteId Returns the ID of the current site. If the current request isn't a site request, then this field returns an empty string.
          $Site.SiteType Returns the API value of the Site Type field for the current site. If the current request isn't a site request, then this field returns an empty string.
          $Site.SiteTypeLabel Returns the value of the Site Type field's label for the current site. If the current request isn't a site request, then this field returns an empty string.

          $System.OriginDateTime

          Description: A global merge field that represents the literal value of 1900-01-01 00:00:00. Use this global variable when performing date/time offset calculations, or to assign a literal value to a date/time field.
          Use:
          • Select the field type: $System.
          • Select OriginDateTime from the Insert Merge Field option.
          Formula Example:

          This example illustrates how to convert a date field into a date/time field. It uses the date in the OriginDateTime merge field to get the number of days since a custom field called My Date Field. Then, it adds the number of days to the OriginDateTime value.

          $System.OriginDatetime + ( My_Date_Field__c - DATEVALUE($System.OriginDatetime) )

          OriginDateTime is in the GMT time zone but the result is displayed in the user’s local time zone.

          Flow, Process, and Visualforce Example:

          This example calculates the number of days that have passed since January 1, 1900:

          {!NOW() - $System.OriginDateTime}
          Tips:

          This global variable is available in:

          • Default values
          • Flows
          • Formulas in custom fields, processes, and workflow rules
          • Workflow field update actions
          • Visualforce pages and s-controls

          $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. Most of the fields available on the User standard object are also available on $User.
          Use:
          • Select the field type: $User.
          • Select a merge field such as $User.Username.
          Validation Rule Example:

          This validation rule formula references the ID of the current user to determine if the current user is the owner of the record. .. Use an example like this to ensure that only the record owner or users with an administrator profile can make changes to a custom field called Personal Goal:

          AND(
              ISCHANGED( Personal_Goal__c ), 
              Owner <> $User.Id, 
              $Profile.Name <> "Custom: System Admin" 
          )
          Flow Example:

          Create a flow formula (Text) that has this expression.

          {!$User.FirstName} & “ “ & {!$User.LastName}

          Once you create that formula, reference it anywhere that you need to call the user by name in your flow. By referencing the $User global variable, you avoid using a Get Records element, which counts against flow limits.

          Visualforce Example:

          This 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>
              <p>This is your new Apex Page</p>
              <p>
                  The current company name for this user is: {!$User.CompanyName}
              </p>
              <p>
                  Is the user active?
                  {!$User.isActive}
              </p>
          </apex:page>
          Tips:
          • The current user is the person changing the record that prompted the default value, validation rule, or other operation that uses these global merge fields.
          • When a Web-to-Case or Web-to-Lead process changed a record, the current user is the Default Lead Owner or Default Case Owner.
          • When a process executes scheduled actions and the user who started the process is no longer active, $User refers to the default workflow user. The same goes for time-based actions in workflow rules.
          • Some of the $User merge fields can be used in mobile configuration filters.

          $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 the user is supposed to see, while $User.UIThemeDisplayed returns the look and feel the user actually sees. For example, a user can have the preference and permissions to see the Lightning Experience look and feel, but if they’re using a browser that doesn’t support that look and feel, for example, older versions of Internet Explorer, $User.UIThemeDisplayed returns a different value.

          Running Classic and Lightning Experience in different browser tabs or windows isn't supported and can cause unexpected behavior in the look and feel of your org and the values returned by the $User.UITheme and $User.UIThemeDisplayed fields. For example, if your org is using Lightning Experience, but you switch to Classic in a different browser tab, these fields return a Classic theme in both tabs.

          Use:

          Use these variables to identify the CSS used to render Salesforce web pages to a user. Both variables return one of these values.

          • Theme1—Obsolete Salesforce theme
          • Theme2—Salesforce Classic 2005 user interface theme
          • Theme3—Salesforce Classic 2010 user interface theme
          • Theme4d—Modern “Lightning Experience” Salesforce theme
          • Theme4t—Salesforce mobile app theme
          • Theme4u—Lightning Console theme
          • PortalDefault—Salesforce Customer Portal theme
          • Webstore—AppExchange theme
          Visualforce Example:

          This 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 == 'Theme3'}">
                 // this is the classic theme ...
              </apex:pageBlock>
          </apex:page>

          $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:
          • Select the field type: $UserRole.
          • Select a merge field, such as $UserRole.Name.
          Validation Rule Example:

          This validation rule formula references the user role name to validate that a custom field called Discount Percent doesn't exceed the maximum value allowed for that role:

          Discount_Percent__c > VLOOKUP(
              $ObjectType.Role_Limits__c.Fields.Limit__c,
              $ObjectType.Role_Limits__c.Fields.Name, 
              $UserRole.Name
          )
          Process, Flow, and Visualforce Example:
          {!$UserRole.LastModifiedById}
          Tips:
          • The current user is the person changing the record that prompted the default value, validation rule, or other operation that uses these global merge fields.
          • When a Web-to-Case or Web-to-Lead process changed a record, the current user is the Default Lead Owner or Default Case Owner.
          • When a process executes scheduled actions and the user who started the process is no longer active, $UserRole refers to role of the default workflow user. The same goes for time-based actions in workflow rules.

          You can’t use these $UserRole values in Visualforce:

          • CaseAccessForAccountOwner
          • ContactAccessForAccountOwner
          • OpportunityAccessForAccountOwner
          • PortalType
          .
           
          Loading
          Salesforce Help | Article