UserInfo Class

Contains methods for obtaining information about the context user.

System

The following are methods for UserInfo. All methods are static.

  • getCurrentUvid()

    Returns the context guest user’s unique visitor ID (UVID).

  • getDefaultCurrency()

    Returns the context user’s default currency code for multiple currency organizations or the organization’s currency code for single currency organizations.

  • getFirstName()

    Returns the context user’s first name

  • getLanguage()

    Returns the context user’s language

  • getLastName()

    Returns the context user’s last name

  • getLocale()

    Returns the context user’s locale.

  • getName()

    Returns the context user’s full name. The format of the name depends on the language preferences specified for the organization.

  • getOrganizationId()

    Returns the context organization’s ID.

  • getOrganizationName()

    Returns the context organization’s company name.

  • getProfileId()

    Returns the context user’s profile ID.

  • getSessionId()

    Returns the session ID for the current session.

  • getTimeZone()

    Returns the current user’s local time zone.

  • getUiTheme()

    Returns the preferred theme for the current user. Use getUiThemeDisplayed to determine the theme actually displayed to the current user.

  • getUiThemeDisplayed()

    Returns the theme being displayed for the current user.

  • getUserEmail()

    Returns the current user’s email address.

  • getUserId()

    Returns the context user’s ID

  • getUserName()

    Returns the context user’s login name.

  • getUserRoleId()

    Returns the context user’s role ID.

  • getUserType()

    Returns the context user’s type.

  • hasPackageLicense(packageId)

    Returns true if the context user has a license to the managed package via a package license only. Otherwise, returns false.

  • isCurrentUserLicensed(namespace)

    Returns true if the context user has a license to any managed package denoted by the namespace. Otherwise, returns false.

  • isCurrentUserLicensedForPackage(packageID)

    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.

  • isMultiCurrencyOrganization()

    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 theme
  • Theme2—Salesforce Classic 2005 user interface theme
  • Theme3—Salesforce Classic 2010 user interface theme
  • Theme4d—Modern “Lightning Experience” Salesforce theme
  • Theme4t—Salesforce mobile app theme
  • Theme4u—Lightning Console theme
  • PortalDefault—Salesforce Customer Portal theme that applies to Customer Portals only and not to Experience Builder sites
  • Webstore—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 theme
  • Theme2—Salesforce Classic 2005 user interface theme
  • Theme3—Salesforce Classic 2010 user interface theme
  • Theme4d—Modern “Lightning Experience” Salesforce theme
  • Theme4t—Salesforce mobile app theme
  • Theme4u—Lightning Console theme
  • PortalDefault—Salesforce Customer Portal theme that applies to Customer Portals only and not to Experience Builder sites
  • Webstore—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)

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)

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)

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