Global Variables

18 Nov
Global Variables

Salesforce provides a variety of global variables for use in formula fields, Visual Flow, Visualforce pages, and other places. But what are global variables anyway?

What are Global Variables?

Global variables are “merge fields” that are used to access information about the current state of the platform, such as information about the current Organization, current User, and current Record. These variables always begin with the dollar character (“$”).

 Examples of Global Variables

  • $Api
  • $Label
  • $Organization
  • $Permission
  • $Profile
  • $RecordType
  • $Resource
  • $Setup
  • $System
  • $User
  • $UserRole


What is a “Merge” Field?

A merge field is a field that must be paired with another merge field in order to return a value. (The clue here is in the word “merge,” a “merge” field must be “merged” with another “merge” field in order to yield a value!)

Examples of Global Variable – Merge Field Pairs

  • $Label.customLabelName
  • $Organization.Name, $Organization.Country
  • $Permission.customPermissionName
  • $Profile.Name
  • $RecordType.Name, $RecordType.Id
  • $Resource.nameOfResource
  • $Setup.CustomSettingName__c.CustomFieldName__c
  • $User.Firstname, $User.Lastname, $User.Id
  • $UserRole.Name


What Do Global Variables Do?

Here is how I think about global variables. I imagine that Salesforce has an object that has a bunch of fields and each field is a pointer to the current object. Now I have no idea if this is really the case, it just helps me make sense of it in my head.

Global Variables - My Perspective

Global Variables – My Perspective

We can access values in fields on current objects by using the global (“$”) field name combined with a field name on the current object in the dot-notation syntax.

For instance, to get the user’s first name we would use $User.Firstname, exactly like referencing a field on any object (Account.Name).

Where Can Global Variables Be Used?

Global variables can be used in a variety of places:

  • Custom formula fields
  • Visual Flow and Process Builder
  • Workflow
  • Validation rules
  • Visualforce pages
  • Apex classes and triggers

The list of variables, however, varies from place to place as well as whether or not certain resources are being utilized. For instance, the list of global variables available in a Formula field will be different than the list in Visual Flow. And certain global variables, like $Label and $Permission will not be available until those resources are used.

Here is are examples of global variables available in a formula field:

Changing List of Global Variables

Changing List of Formula Field Global Variables

You can see that the list on the left does not contain $Label or $Permission. That is because in the org on the left the Label and Permissions resources have not been used.

Using Global Variables

So that’s my quick explanation of global variables. I’ll post a bit more detail on some of these variables in a bit.



Leave a comment

Posted by on November 18, 2015 in Global Variables



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: