What are Salesforce global variables?
Global variables are system-provided references you can use inside Salesforce formulas and validation rules to get information about the current user, organization, labels, custom settings, and permissions. They make formulas dynamic and maintainable by avoiding hard-coded values.
Common global variables and when to use them
$User
Returns details about the running user. Useful for user-based logic (owner checks, email, locale, etc.).
$User.Id, $User.FirstName, $User.Email, $User.ProfileId
Example: prevent updating a record by everyone except the owner or a particular user:
AND(NOT($User.Id = OwnerId), IsClosed = TRUE)
$Profile
Returns properties of the current user’s profile. Use it to restrict behavior by profile.
$Profile.Name, $Profile.Id
Example: show an error if a non-admin profile attempts a change:
AND($Profile.Name <> "System Administrator", IsActive = FALSE)
$Organization
Provides org-level metadata (useful for multi-org logic or debug settings).
$Organization.Id, $Organization.Name
Example: apply special logic for a sandbox or specific org:
$Organization.Id = "00Dxxxxxxxxxxxx"
$Setup
Access hierarchical custom settings values from formulas and validation rules. This is great for configuration without changing the formula itself.
$Setup.My_Custom_Setting__c.Default_Value__c
Example: compare a field against a threshold stored in a custom setting:
Amount > $Setup.Limits__c.Max_Deal_Amount__c
$Label
Reference custom labels to keep messages and text translatable and maintainable.
$Label.My_Custom_Label
Example: use label text inside a formula-driven field or validation message (often used in UI or error messaging contexts).
$Permission
Check Custom Permissions in formulas and validation rules (returns true/false). Useful for feature flags or baked-in privileges.
$Permission.My_Custom_Permission
Example: allow an override only if the user has a custom permission:
$Permission.Allow_Discount_Override && Discount__c > 0
$UserRole
Information about the running user’s Role. Less commonly used in formulas, but available when role-based logic is required.
$UserRole.Id, $UserRole.Name
Best practices
- Prefer $Setup and $Label for configurable values and text so formulas don’t contain hard-coded values.
- Use $Permission for feature toggles and to avoid mixing admin logic into profiles hard-coded checks.
- Keep formulas readable: comment or document complex formulas elsewhere if the formula editor gets long.
- Test formulas with different user contexts (different profiles/roles/custom permissions) when possible.
Quick reference — sample snippets
Block non-admin users from closing opportunities:
AND(IsClosed = TRUE, $Profile.Name <> "System Administrator")
Use custom setting threshold:
Amount > $Setup.Deal_Settings__c.Max_Amount__c
Enable logic for users with a custom permission:
$Permission.Approval_Bypass && ISPICKVAL(Status, "Approved")
Summary: Use global variables to keep formulas dynamic, secure, and configurable. The most commonly used are $User, $Profile, $Organization, $Setup, $Label, and $Permission.








Leave a Reply