Global Variables in Salesforce - All You Need To Know

Global Variables in Salesforce – All You Need To Know

Global-Variables-in-Salesforce---All-You-Need-To-Know

Global variables are defined as a special type of merge fields provided by the Salesforce referencing the data in your organization. These are used to access and display the user and organization information, perform standard actions on records such as creation, deletion etc. These are easily identified as they start with the ‘$’ sign. Any fields of the global variables can be accessed by using the expression in the form of {! $GlobalName.fieldName}. In this article, we will be explaining the usage of global variables in various components, a simple example and the types of global variables.

Where the global variables are used?

Global variables are used in the following components of Salesforce:

  • visualforce pages
  • flows
  • formulas
  • validation rules
  • process builder
  • custom buttons and links

Example:

For example, let’s consider there is a visualforce page that would display the information about the currently logged-in user to the organization. This can be achieved by using the global variable called ‘$User’. The information about the user is accessed by using the expression {! $User.fieldName}.

Connect-Salesforce-ERP

Types of Global variables:

There are different types of global variables with distinct functionality. Below are some of the most commonly used global variables in Salesforce.

$Action:

It is a global merge field type used for referencing standard Salesforce actions such as creating, updating and deleting the records. It is a merge field with the format $Action.object.action.

Example: The below example references to the standard action for creating a new account using $Action.Account.New merge field in a visualforce page.

<apex:outputLink value="{!URLFOR($Action.Account.New)}">Create New Account</apex:outputLink>

Following are the few actions performed with $Action global variable:

  • $Action.Product2.Add: It adds a product to a price book. This is only available for product objects.
  • $Action.Product2.Clone: It clones a record. This is available for contact, lead, case, and product, etc.
  • $Action.Attachment.Download: It downloads an attachment. This is used for attachment and documents

Usage: This global variable is used custom buttons and links, and Visualforce pages.

$Api:

It is a global merge field type used for referencing API URLs.

Example: {!$Api.Session_ID} returns the session id of the current session.

The following are the expressions used with $Api  global merge field.

  • {!$Api.Enterprise_Server_URL__xxx}: It is an enterprise WSDL SOAP endpoint where xxx represents the version of the API. For example, {!$Api.Enterprise_Server_URL_440} expression references to the version 44.0 of the API
  • {!$Api.Partner_Server_URL__xxx}: It is a partner WSDL SOAP endpoint where xxx represents the version of the API.

Usage: This global variable is used custom buttons and links, Visualforce pages, flow formulas, and process formulas.

Connect-Salesforce-ERP

$ObjectType:

It is a global merge field type used for referencing standard and custom objects and the values of their fields.

Example

  • {!$ObjectType.Account.Fields.Name.Label} returns the label for the Account name.
  • {!$ObjectType.Account.Fields.Name.Type} returns the data type of the Account name.

Usage: This global variable is used custom buttons and links, Visualforce pages, and validation rules.

$Organization:

It is a global merge field type used for referencing information about an organizational profile.

Example:

  • {!$Organization.Country} returns the value of a country that is currently stored as part of your company information in Salesforce.
  • {!$Organization.Phone} returns the value of the phone that is currently stored as part of your company information in Salesforce.

Usage: This global variable is used in custom fields, validation rules, Visualforce expressions, flow formulas, process formulas, and workflow rules.

$Page:

It is a global merge field type used for referencing another visual force page.

Example: The following example provides a link to a visualforce page ‘otherVFPagename’.

<apex:page>

  <h1>Linked</h1>

  <apex:outputLink value="{!$Page.otherVFagename}">

    This is a link to another page.

  </apex:outputLink>

</apex:page>

Usage: This global variable is only available for visual force pages.

$User:

It is a global merge field type used for referencing the information about the currently logged-in user to the organization.

Example: 

  • {!$User.Username} returns the username of currently logged in Salesforce user.
  • {!$User.isActive} returns the active status of the logged in user.

Usage: This global variable is used custom buttons and links, Visualforce pages, validation rules.

Connect-Salesforce-ERP

$Permission:

It is a global merge field type used for referencing the current logged in user’s custom permissions (which gives the user access to custom processes or apps) access.

Example:

  • $Permission.customPermissionName will return the true if the current user has an access to custom permission

Usage: This global variable is used custom buttons and links, Visualforce pages, validation rules.

Conclusion:

This article explains the usage of global variables, types of global variables with few examples. We sincerely hope that this was useful and any comment of feedback will be very helpful.

Now, you can easily integrate your Salesforce CRM with the back-end ERP system to automate the business process!Connect-Salesforce-ERP

You may also like:
Configuring Cash Sales within SAP ERP – Everything You Need To Know!
Understanding Roles in Salesforce
Configuring Sales Order Reasons within SAP

Team Veon