Global Variables in Salesforce pertain to details on information about users, records and the current state of the organization as a whole. The variables are for use in Visualforce pages, Visual Flow pages, formula fields and other places.
Examples of Global Variables
Names of these variables start with the dollar symbol ($).
- $System
- $Api
- $Organization
- $Label
- $Profile
- $Setup
- $User
- $Permission
- $RecordType
- $Resource
- $UserRole
What Are Merged Fields?
Global Variables are also called merged fields. In truth, what are operational in the software are merged fields. A merged field is combined with another merged field, so that together, they can return a value or give a report.
Below are examples of merged field pairs:
- $Label.customLabelName
- $RecordType.Name, $RecordType.Id
- $Organization.Name, $Organization.Country
- $Profile.Name
- $Permission.customPermissionName
- $Resource.nameOfResource
- $UserRole.Name
How Does a Global Variable Function?
One can put it this way. Imagine Salesforce to be having hundreds or even thousands of fields. Each field is pointing to an object. Users can then access values by making use of that system.
In the names above, the dollar sign represents the search process used by Salesforce. The combination of the field name and the object expressed in the dot-notation syntax tells the system from which object must the data come from.
Where to Use Variables
Global variables are used in different places, such as:
- Apex classes and triggers
- Validation rules
- Workflow
- And the three mentioned above.
Variables that appear in one place usually differ from the ones that appear in another place. It depends on whether or not certain Salesforce resources are used. For example, the list in Visual Flow differs from the list of variables in Validation Rules. Also, variables, like $Permission and $UserRole, will not appear on any list until they are utilized.