UserInfo Class
Contains methods for obtaining information about the context user.
The following are methods for UserInfo. All methods are static.
-
Returns the context guest user’s unique visitor ID (UVID).
-
Returns the context user’s default currency code for multiple currency organizations or the organization’s currency code for single currency organizations.
-
Returns the context user’s first name
-
Returns the context user’s language
-
Returns the context user’s last name
-
Returns the context user’s locale.
-
Returns the context user’s full name. The format of the name depends on the language preferences specified for the organization.
-
Returns the context organization’s ID.
-
Returns the context organization’s company name.
-
Returns the context user’s profile ID.
-
Returns the session ID for the current session.
-
Returns the current user’s local time zone.
-
Returns the preferred theme for the current user. Use
getUiThemeDisplayedto determine the theme actually displayed to the current user. -
Returns the theme being displayed for the current user.
-
Returns the current user’s email address.
-
Returns the context user’s ID
-
Returns the context user’s login name.
-
Returns the context user’s role ID.
-
Returns the context user’s type.
-
Returns
trueif the context user has a license to the managed package via a package license only. Otherwise, returnsfalse. -
isCurrentUserLicensed(namespace)
Returns
trueif the context user has a license to any managed package denoted by the namespace. Otherwise, returnsfalse. -
isCurrentUserLicensedForPackage(packageID)
Returns
trueif the context user has a license to the managed package denoted by the package ID. Otherwise, returnsfalse. If the context user has access, it’s determined either via the package license or a namespace permission set license for the package namespace. -
Specifies whether the organization uses multiple currencies.
Returns the context guest user’s unique visitor ID (UVID).
public static String getCurrentUvid()
Type: String
If a UVID isn’t available, returns null.
Returns the context user’s default currency code for multiple currency organizations or the organization’s currency code for single currency organizations.
public static String getDefaultCurrency()
Type: String
For Apex saved using Salesforce API version 22.0 or earlier, getDefaultCurrency returns null for single currency organizations.
Returns the context user’s first name
public static String getFirstName()
Type: String
Returns the context user’s language
public static String getLanguage()
Type: String
Returns the context user’s last name
public static String getLastName()
Type: String
Returns the context user’s locale.
public static String getLocale()
Type: String
Returns the context user’s full name. The format of the name depends on the language preferences specified for the organization.
public static String getName()
Type: String
The format is one of the following:
- FirstName LastName
- LastName, FirstName
Returns the context organization’s ID.
public static String getOrganizationId()
Type: String
Returns the context organization’s company name.
public static String getOrganizationName()
Type: String
Returns the context user’s profile ID.
public static String getProfileId()
Type: String
Returns the session ID for the current session.
public static String getSessionId()
Type: String
You can use getSessionId() both synchronously and asynchronously. In asynchronous Apex (Batch, Future, Queueable, or Scheduled Apex), this method returns the session ID only when the code is run by an active, valid user. When the code is run by an internal user, such as the automated process user or a proxy user, the method returns null.
As a best practice, ensure that your code handles both cases: when a session ID is or is not available.
If you use a JWT-based access token for session authentication, you can’t use UserInfo.getSessionId(). To use UserInfo.getSessionId(), use an opaque access token instead. Ensure that the “Issue JSON Web Token (JWT)-based access tokens for named users” setting isn’t selected for your external client app or connected app.
Returns the current user’s local time zone.
public static System.TimeZone getTimeZone()
Type: System.TimeZone
Returns the preferred theme for the current user. Use getUiThemeDisplayed to determine the theme actually displayed to the current user.
public static String getUiTheme()
Type: String
The preferred theme for the current user.
Valid values include:
Theme1—Obsolete Salesforce themeTheme2—Salesforce Classic 2005 user interface themeTheme3—Salesforce Classic 2010 user interface themeTheme4d—Modern “Lightning Experience” Salesforce themeTheme4t—Salesforce mobile app themeTheme4u—Lightning Console themePortalDefault—Salesforce Customer Portal theme that applies to Customer Portals only and not to Experience Builder sitesWebstore—AppExchange theme
Returns the theme being displayed for the current user.
public static String getUiThemeDisplayed()
Type: String
The theme being displayed for the current user
Valid values include:
Theme1—Obsolete Salesforce themeTheme2—Salesforce Classic 2005 user interface themeTheme3—Salesforce Classic 2010 user interface themeTheme4d—Modern “Lightning Experience” Salesforce themeTheme4t—Salesforce mobile app themeTheme4u—Lightning Console themePortalDefault—Salesforce Customer Portal theme that applies to Customer Portals only and not to Experience Builder sitesWebstore—AppExchange theme
Returns the current user’s email address.
public static String getUserEmail()
Type: String
Returns the context user’s ID
public static String getUserId()
Type: String
Returns the context user’s login name.
public static String getUserName()
Type: String
Returns the context user’s role ID.
public static String getUserRoleId()
Type: String
Returns the context user’s type.
public static String getUserType()
Type: String
Returns true if the context user has a license to the managed package via a package license only. Otherwise, returns false.
public static Boolean hasPackageLicense(ID packageID)
-
packageID:
Type: String
Type: Boolean
Returns true if the context user has a license to any managed package denoted by the namespace. Otherwise, returns false.
public static Boolean isCurrentUserLicensed(String namespace)
-
namespace:
Type: String
Type: Boolean
A TypeException is thrown if namespace is an invalid type.
Returns true if the context user has a license to the managed package denoted by the package ID. Otherwise, returns false. If the context user has access, it’s determined either via the package license or a namespace permission set license for the package namespace.
public static Boolean isCurrentUserLicensedForPackage(ID packageID)
-
packageID:
Type: String
Type: Boolean
Retrieve packageID at runtime, with the getCurrentPackageId() method. Then, use packageId to confirm that the contextual user is licensed to use that managed package.
A TypeException is thrown if packageID is an invalid type or is the ID of an unlocked or unmanaged package.
See Also
Specifies whether the organization uses multiple currencies.
public static Boolean isMultiCurrencyOrganization()
Type: Boolean