Global Variable
A Global Variable in Salesforce is a system-provided value, prefixed with a dollar sign, that gives formulas, Visualforce pages, Lightning Web Components, Aura components, and other declarative tools access to contextual information about the current user, organization, environment, or platform metadata.
Definition
A Global Variable in Salesforce is a system-provided value, prefixed with a dollar sign, that gives formulas, Visualforce pages, Lightning Web Components, Aura components, and other declarative tools access to contextual information about the current user, organization, environment, or platform metadata. Common examples include $User (current user fields like $User.Id, $User.Email, $User.ProfileId), $Profile (current user's profile fields), $Organization (org-level fields like $Organization.Id), $Setup (custom setting values), $Label (custom label values for translated text), $Action (URL or behavior for standard actions), and $Resource (static resource references).
Global Variables are how declarative customizations access information that would otherwise require Apex or SOQL. A formula field can reference $User.ProfileId without writing any code; a Visualforce page can show $Organization.Name without binding to a controller property; a Lightning Web Component can read $Resource references to images without computing URLs. The result is significantly simpler customization for the common cases where the system context (who is the user, what is the org, what time is it) determines behavior. Mastering Global Variables is one of the steps that distinguishes a productive admin from one who hits the limits of declarative tools quickly.
The catalog of Global Variables
$User and user context variables
The $User Global Variable exposes the current user's record fields: $User.Id, $User.FirstName, $User.LastName, $User.Email, $User.Username, $User.Title, $User.Department, $User.Manager, $User.Profile, $User.Role, $User.UserType, $User.Timezone, $User.Locale, $User.LanguageLocaleKey. Formulas use these to drive context-aware behavior: a validation rule that requires an approval only if $User.Profile.Name does not contain Manager; a Flow that branches based on $User.Department; a Lightning component that personalizes its display based on $User.LanguageLocaleKey. The $User variable is one of the most heavily used Global Variables across the platform.
$Profile and $Permission variables
The $Profile Global Variable exposes the current user's profile, and $Permission exposes the user's effective permissions. Formulas use $Profile.Name to check the user's profile name (often used in validation rules: skip the rule if profile is System Administrator). $Permission.YourPermissionApiName returns true or false based on whether the user has a specific permission, which lets formulas check permissions without complex Apex logic. These variables are valuable for building permission-aware customizations that adjust behavior based on what the current user can do.
$Organization and $Setup variables
The $Organization Global Variable provides org-level information: $Organization.Id (the 15-character org ID), $Organization.Name, $Organization.GeocodeAccuracy, $Organization.UiSkin, $Organization.IsSandbox (often used to differentiate sandbox versus production behavior). The $Setup Global Variable provides access to Hierarchy Custom Settings: $Setup.MySetting__c.MyField__c returns the appropriate value based on the user-org-default hierarchy. Custom Settings remain the standard way to expose configurable values to formulas; Custom Metadata Types are more powerful but accessed differently through $CustomMetadata.
$Label and translation variables
Custom Labels are translatable text strings accessed through $Label. A Visualforce page that displays {!$Label.WelcomeMessage} shows the right translated text based on the user's Language Locale Key. The Custom Labels themselves are configured in the Translation Workbench, with translations provided per language. The pattern lets a single Visualforce page or Lightning component serve users in multiple languages without duplicating the markup. For global organizations, $Label is one of the most important Global Variables because it enables consistent localization across the platform without manual coordination per page.
$Resource and $Site variables
The $Resource Global Variable provides references to Static Resources: $Resource.MyImage returns the URL of the static resource named MyImage. The pattern lets Visualforce and Lightning components reference static assets (images, scripts, stylesheets) without hardcoding the underlying URL, which would break across org migrations. $Site provides information about the active Salesforce Site (if running in a Sites context): $Site.Domain, $Site.Prefix, $Site.AnalyticsTrackingCode. These variables are essential for any customization that serves both internal and external (Site-hosted) traffic, where the URL structure differs significantly.
$Action and $ObjectType variables
The $Action Global Variable references standard URL actions: $Action.Account.New returns the URL to create a new Account record, $Action.Case.Submit_For_Approval returns the URL to submit a Case for approval. The pattern lets formula fields and components produce action URLs without hardcoding them, which preserves the URL across Lightning Experience versus Classic and across Hyperforce migrations. $ObjectType returns the API name of a referenced object: $ObjectType.Account.Fields.Industry returns Account.Industry. The variable is useful in metadata-driven contexts where the object name needs to be programmatically determined.
$Api and $Component variables in Visualforce
Visualforce-specific Global Variables include $Api (giving access to the API endpoint URLs: $Api.Partner_Server_URL_360 returns the partner SOAP API URL for the current org) and $Component (giving access to specific Visualforce component IDs by name). These are less commonly used in modern development but remain available for Visualforce pages that need to integrate with external services or reference specific components dynamically. Lightning Web Components have their own equivalent patterns for these needs through the modules @salesforce/user and @salesforce/i18n.
$CustomMetadata and configuration access
The $CustomMetadata Global Variable provides formula access to Custom Metadata Type records, the modern alternative to Custom Settings for configuration data. Custom Metadata Types are deployable through Change Sets and Salesforce DX (unlike Custom Settings, which require manual data load per environment), and $CustomMetadata.MyType__mdt.MyRecord__r.MyField__c references the value cleanly in formulas. For new configuration needs, Custom Metadata Types accessed through $CustomMetadata are usually the right choice over List Custom Settings. The migration from Custom Settings to Custom Metadata Types is a common modernization task in mature orgs, and $CustomMetadata is what makes the migrated configuration accessible in declarative tools the same way $Setup makes the original configuration accessible.
$Profile usage in validation rules
One of the most common patterns in Salesforce validation rules is using $Profile.Name to skip the rule for specific user groups: NOT(CONTAINS($Profile.Name, 'System Administrator')) lets the rule fire for everyone except system admins. The pattern is occasionally controversial (some governance approaches argue that bypassing rules for admins is a smell rather than a feature) but it remains widely used because it gives admins the operational flexibility to override rules when business situations demand it. A related pattern uses $Permission instead of $Profile, checking for a specific bypass permission that can be granted via Permission Set: $Permission.Bypass_Validation_Rules. The Permission-based pattern is cleaner because it supports granting and revoking the bypass independently of the profile, and it integrates with the org's broader permission governance.
Common pitfalls with Global Variables
Three pitfalls recur with Global Variable usage. Null reference errors when a referenced field is empty for some users: formulas that compute $User.Manager.Email crash when the user has no manager. The fix is null-safe formula logic using ISBLANK or BLANKVALUE. Case sensitivity in $Permission API names: the names are case-sensitive and must match exactly the Permission API Name as configured. Misspellings produce silent false-evaluation rather than errors, which is easy to miss in testing. Environment differences in $Organization: $Organization.IsSandbox returns different values in sandbox versus production, which is the right behavior but sometimes surprises developers who expect a single value. Each pitfall is preventable with careful testing, but they all recur in real codebases.
Use Global Variables effectively
Global Variables are most useful when admins know which one to reach for in each scenario. The workflow below covers the standard patterns for using Global Variables across formulas, Visualforce, and Lightning components.
- Identify the context the customization needs
Decide what contextual information the customization requires: the current user's identity, their profile, the org's configuration, a translated label, a static resource reference. Match the requirement to the right Global Variable from the catalog. For common scenarios (current user, profile, org), the Global Variable choice is obvious. For less common ones, the developer documentation lists every available variable with its fields.
- Reference the variable in formulas, Visualforce, or Lightning
Reference the Global Variable using the appropriate syntax. In formulas: $User.Profile.Name. In Visualforce: {!$User.Profile.Name}. In Lightning Web Components: import from @salesforce/user or use specific user-info APIs. The syntax differs slightly per tool but the underlying values are the same. Test the customization with multiple user contexts to confirm the variable resolves correctly for each.
- Handle null and missing values
Some Global Variable fields may return null in certain contexts: a user without a manager has $User.Manager equal to null. Formulas that reference such fields need null handling: ISBLANK($User.Manager) returns true for users without a manager. Visualforce expressions and Lightning component code should similarly guard against null values. Test the customization with edge-case users (no manager, no department, no specific permission) to confirm the null handling works.
- Document and maintain the usage
Document which Global Variables the customization uses and why. Future maintainers benefit from knowing the context dependencies. Watch for any Salesforce release notes that change Global Variable behavior (new fields added, deprecation of specific variables, behavior changes between Classic and Lightning). Update the customization if any referenced field is deprecated or changed.
- Global Variable fields can return null. Always handle null values in formulas and Visualforce code that references them.
- $Permission API names use the underlying permission identifier, not the human-readable label. Looking up the right name requires the Setup permissions page.
- $Setup variable accesses Hierarchy Custom Settings only. List Custom Settings use a different access pattern.
- $Label values change based on the user's language. Test the customization in each supported language to confirm the text renders correctly.
- Some Global Variables are Lightning-only or Classic-only. Cross-experience customizations may need fallback handling.
Trust & references
Straight from the source - Salesforce's reference material on Global Variable.
- Formula Operators and FunctionsSalesforce Help
- Visualforce Global VariablesSalesforce Developer Docs
Hands-on resources to go deeper on Global Variable.
About the Author
Dipojjal Chakrabarti is a B2C Solution Architect with 29 Salesforce certifications and over 13 years in the Salesforce ecosystem. He runs salesforcedictionary.com to help admins, developers, architects, and cert/interview candidates sharpen their fundamentals. More about Dipojjal.
Test your knowledge
Q1. What's a Global Variable in Salesforce?
Q2. What's an example of a global variable?
Q3. Why use global variables?
Discussion
Loading discussion…