Overview
Salesforce global variables let you reference metadata and context (current user, org, profile, labels, permissions) directly in formulas and validation rules. Knowing the most common global variables speeds up building dynamic business logic and reduces hard-coded values.
Common Global Variables
$User
Represents the current user and exposes fields such as Id, Email, Username, FirstName, LastName, and ProfileId. Useful for rule checks tied to the running user.
$User.Id
$Profile
Provides information about the current user’s profile. Commonly used to allow or block actions based on profile name or Id.
$Profile.Name
$Organization
Contains organization-level details such as name, default locale, country, or instance information. Good for org-wide conditional logic in formulas.
$Organization.Id
$Label
Reference custom labels stored in Salesforce. Use this to keep messages and text translatable and maintainable.
$Label.My_Custom_Label
$Resource
Access static resources from formulas (for example, image URLs or hosted assets used in Visualforce or other contexts).
$Resource.Image_Asset_Name
$Permission
Evaluate whether the running user has a specific custom permission. Useful in validation rules to bypass or apply rules depending on permissions.
$Permission.My_Custom_Permission
Global Constants
Salesforce also exposes boolean/null constants usable in formulas:
TRUE, FALSE, NULL
Practical Examples
1. Prevent edit unless owner or admin
AND(ISCHANGED(OwnerId), OwnerId <> $User.Id, $Profile.Name <> "System Administrator")
This rule blocks changing the owner unless the current user is the owner or is a System Administrator.
2. Show a translated error message using a custom label
ISBLANK(Phone) ? $Label.Phone_Required_Error : NULL
Use $Label to keep messages translatable and easy to update without changing formulas.
3. Skip validation for users with a custom permission
AND(ISPICKVAL(Status, "Closed"), NOT($Permission.Skip_Close_Validation))
Users granted the custom permission Skip_Close_Validation will bypass the validation rule.
Best Practices
- Prefer $Label and $Permission for maintainability and internationalization.
- Avoid hard-coding profile names or IDs where possible—use custom permissions when you can.
- Test validation rules thoroughly with users having different profiles and permissions.
Keywords: Salesforce global variables, formulas, validation rules, $User, $Profile, $Organization, $Label, $Permission
Leave a Reply