---
schema_version: "1"
id: b95c2947cebed9566970e406647177c1d9ac0df2a04ba030514c7b882b61c0d4
title: Salesforce Sites-Related Apex Methods and Expressions
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/platform/264-0-0/sites_apex_methods_and_merge_fields.md
canonical_url: https://help.salesforce.com/s/articleView?id=platform.sites_apex_methods_and_merge_fields.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 8597fe312d5df2fd6bd0747cde4b2556842962b1f7bf45c45076ed2209502ab5
description: Lightning Platform provides Apex methods and Salesforce Sites-related expressions to help execute flow and transaction control statements.
products:
  - Salesforce Platform
  - Security
release: "264"
---
# Salesforce Sites-Related Apex Methods and Expressions

Lightning Platform provides Apex methods and Salesforce Sites-related expressions to help execute flow and transaction control statements.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: both Salesforce Classic and Lightning Experience</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: <strong>Developer</strong>, <strong>Enterprise</strong>, <strong>Performance</strong>, and <strong>Unlimited</strong> Editions</td></tr></tbody></table>

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small permission">
      <colgroup>
        <col style="width:50%">
        <col style="width:50%">
      </colgroup>
      <thead class="slds-text-title_caps ">
        <tr class="">
          <th scope="colgroup" class="slds-cell-wrap" colspan="2" style="text-align:center;vertical-align:top;" id="d127945e70">User Permissions
            Needed</th>
        </tr>
      </thead>
      <tbody>
        <tr class="">
          <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e70 ">To create and edit Salesforce Sites:</td>

          <td class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e70 ">
            <p>Customize Application</p>
            <p>OR</p>
            <p style="margin-bottom:0;">Create and Set Up
              Experiences</p>
          </td>

        </tr>
      </tbody>
    </table>

## Lightning Platform Apex Methods

Apex methods for Salesforce Sites are contained in the `site` class, `cookie` class, and `urlRewriter` class. See the [Lightning Platform Apex Code Developer's Guide](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/).

## Salesforce Sites-Related Expressions

Salesforce Sites-related expressions can be used on Visualforce pages, email templates, and s-controls.

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
        <colgroup>
          <col style="width:37.5%">
          <col style="width:62.5%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d127945e135">Merge Field</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d127945e138">Description</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="Merge Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e135 ">$Site.Name</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e138 ">Returns the API name of the current site.</td>

          </tr>
          <tr class="">
            <td data-label="Merge Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e135 ">$Site.Domain</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e138 ">Returns your Salesforce Sites based URL.</td>

          </tr>
          <tr class="">
            <td data-label="Merge Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e135 ">$Site.CustomWebAddress</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e138 ">Returns the request's custom URL if it doesn't end in
              <samp class="filepath">force.com</samp> or returns the site's primary
              custom URL. If neither exist, $Site.CustomWebAddress returns an
              empty string. 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 <code>/</code> character. Use of $Site.CustomWebAddress is
              discouraged and we recommend using $Site.BaseCustomUrl
              instead.
            </td>

          </tr>
          <tr class="">
            <td data-label="Merge Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e135 ">$Site.OriginalUrl</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e138 ">Returns the original URL for this page if it's a designated error
              page for the site; otherwise, returns <code>null</code>.</td>

          </tr>
          <tr class="">
            <td data-label="Merge Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e135 ">$Site.CurrentSiteUrl</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e138 ">Returns the base URL of the current site that references and
              links use. This field can 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 <code>/</code>
              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.</td>

          </tr>
          <tr class="">
            <td data-label="Merge Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e135 ">$Site.LoginEnabled</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e138 ">Returns <code>true</code> if the current
              site is associated with an active login-enabled portal; otherwise
              returns <code>false</code>.</td>

          </tr>
          <tr class="">
            <td data-label="Merge Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e135 ">$Site.RegistrationEnabled</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e138 ">Returns <code>true</code> if the current
              site is associated with an active self-registration-enabled Customer
              Portal; otherwise returns <code>false</code>.</td>

          </tr>
          <tr class="">
            <td data-label="Merge Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e135 ">$Site.IsPasswordExpired</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e138 ">For authenticated users, returns <code>true</code> if the currently logged-in user's password is
              expired. For non-authenticated users, returns <code>false</code>.</td>

          </tr>
          <tr class="">
            <td data-label="Merge Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e135 ">$Site.AdminEmailAddress</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e138 ">Returns an empty string. This merge field is deprecated.</td>

          </tr>
          <tr class="">
            <td data-label="Merge Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e135 ">$Site.Prefix</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e138 ">Returns the URL path prefix of the current site. For example, if
              your site URL is
              <samp class="filepath"><var>MyDomainName</var>.my.salesforce-sites.com/partners</samp>,
              <samp class="filepath">/partners</samp> is the path prefix. Returns
              <code>null</code> if the prefix isn’t
              defined. If the current request isn’t a site request, then this
              field returns an empty string.
            </td>

          </tr>
          <tr class="">
            <td data-label="Merge Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e135 ">$Site.Template</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e138 ">Returns the template name associated with the current site;
              returns the default template if no template has been
              designated.</td>

          </tr>
          <tr class="">
            <td data-label="Merge Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e135 ">$Site.ErrorMessage</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e138 ">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.</td>

          </tr>
          <tr class="">
            <td data-label="Merge Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e135 ">$Site.ErrorDescription</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e138 ">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.</td>

          </tr>
          <tr class="">
            <td data-label="Merge Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e135 ">$Site.AnalyticsTrackingCode</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e138 ">The tracking code associated with your site. Services such as
              Google Analytics can use this code to track page request data for
              your site.</td>

          </tr>
          <tr class="">
            <td data-label="Merge Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e135 ">$Site.BaseCustomUrl</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e138 ">
              <p>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 <code>/</code> character. If all the
                custom URLs in this site end in
                <samp class="filepath">salesforce-sites.com</samp> or if this site has no
                custom URLs, $Site.BaseCustomUrl returns an empty string. If the
                current request isn’t a site request, then this method returns an
                empty string.
              </p>
              <p style="margin-bottom:0;">This field replaces
                <samp class="parmname">CustomWebAddress</samp> and includes the
                custom URL's path prefix.
              </p>
            </td>

          </tr>
          <tr class="">
            <td data-label="Merge Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e135 ">$Site.BaseInsecureUrl</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e138 ">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 <code>/</code> character.
              If the current request isn’t a site request, then this method
              returns an empty string</td>

          </tr>
          <tr class="">
            <td data-label="Merge Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e135 ">$Site.BaseRequestUrl</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e138 ">Returns the base URL of the current site for the requested URL.
              The referring page's URL doesn’t influence $Site.BaseRequestUrl. 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 <code>/</code> character. If the
              current request isn’t a site request, then this method returns an
              empty string.</td>

          </tr>
          <tr class="">
            <td data-label="Merge Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e135 ">$Site.BaseSecureUrl</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e138 ">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 if 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 <code>/</code>
              character. If the current request isn’t a site request, then this
              method returns an empty string.</td>

          </tr>
          <tr class="">
            <td data-label="Merge Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e135 ">$Site.BaseUrl</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e138 ">
              <p>Returns the base URL of the current site that references and
                links use. This field can 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 <code>/</code>
                character. If the current request isn’t a site request, then this
                field returns an empty string.</p>
              <p style="margin-bottom:0;">This field replaces
                $Site.CurrentSiteUrl.</p>
            </td>

          </tr>
          <tr class="">
            <td data-label="Merge Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e135 ">$Site.MasterLabel</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e138 ">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.</td>

          </tr>
          <tr class="">
            <td data-label="Merge Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e135 ">$Site.SiteId</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e138 ">Returns the ID of the current site. If the current request isn’t
              a site request, then this field returns an empty string.</td>

          </tr>
          <tr class="">
            <td data-label="Merge Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e135 ">$Site.SiteType</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e138 ">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.</td>

          </tr>
          <tr class="">
            <td data-label="Merge Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e135 ">$Site.SiteTypeLabel</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d127945e138 ">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.</td>

          </tr>
        </tbody>
      </table>

![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-extend_click-264-0-0-production-enus/5f7d9219-b7b1-4552-8891-f1aba9b289fc/images/icon_note.png)

Note To use these expressions, the Salesforce Sites feature must be enabled for your organization. You must also use them within the context of your public site; otherwise, an empty string is returned for all expressions except {!$Site.Template}, which returns the default template for the site.