UserInfo Class

Contains methods for obtaining information about the context user.

Namespace

System

UserInfo Methods

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

getDefaultCurrency()

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

Signature

public static String getDefaultCurrency()

Return Value

Type: String

Usage

Note
For Apex saved using SalesforceAPI version 22.0 or earlier, getDefaultCurrency returns null for single currency organizations.

getFirstName()

Returns the context user's first name

Signature

public static String getFirstName()

Return Value

Type: String

getLanguage()

Returns the context user's language

Signature

public static String getLanguage()

Return Value

Type: String

getLastName()

Returns the context user's last name

Signature

public static String getLastName()

Return Value

Type: String

getLocale()

Returns the context user's locale.

Signature

public static String getLocale()

Return Value

Type: String

Example

String result = UserInfo.getLocale();
System.assertEquals('en_US', result);

getName()

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

Signature

public static String getName()

Return Value

Type: String

Usage

The format is one of the following:

  • FirstName LastName
  • LastName, FirstName

getOrganizationId()

Returns the context organization's ID.

Signature

public static String getOrganizationId()

Return Value

Type: String

getOrganizationName()

Returns the context organization's company name.

Signature

public static String getOrganizationName()

Return Value

Type: String

getProfileId()

Returns the context user's profile ID.

Signature

public static String getProfileId()

Return Value

Type: String

getSessionId()

Returns the session ID for the current session.

Signature

public static String getSessionId()

Return Value

Type: String

Usage

For Apex code that is executed asynchronously, such as @future methods, Batch Apex jobs, or scheduled Apex jobs, getSessionId returns null.

As a best practice, ensure that your code handles both cases – when a session ID is or is not available.

getTimeZone()

Returns the current user’s local time zone.

Signature

public static System.TimeZone getTimeZone()

Return Value

Type: System.TimeZone

Example

TimeZone tz = 
  UserInfo.getTimeZone();
System.debug(
  'Display name: ' + 
  tz.getDisplayName());
System.debug(
  'ID: ' + 
  tz.getID());

getUiTheme()

Returns the default organization theme. Use getUiThemeDisplayed to determine the theme actually displayed to the current user.

Signature

public static String getUiTheme()

Return Value

Type: String

The default organization theme.

Valid values include:
  • Theme1
  • Theme2
  • Theme3
  • Theme4
  • PortalDefault
  • Webstore

getUiThemeDisplayed()

Returns the theme being displayed for the current user.

Signature

public static String getUiThemeDisplayed()

Return Value

Type: String

The theme being displayed for the current user

Valid values include:
  • Theme1
  • Theme2
  • Theme3
  • Theme4
  • PortalDefault
  • Webstore

getUserEmail()

Returns the current user’s email address.

Signature

public static String getUserEmail()

Return Value

Type: String

Example

String emailAddress = 
  UserInfo.getUserEmail();
System.debug(
  'Email address: ' + 
  emailAddress);

getUserId()

Returns the context user's ID

Signature

public static String getUserId()

Return Value

Type: String

getUserName()

Returns the context user's login name.

Signature

public static String getUserName()

Return Value

Type: String

getUserRoleId()

Returns the context user's role ID.

Signature

public static String getUserRoleId()

Return Value

Type: String

getUserType()

Returns the context user's type.

Signature

public static String getUserType()

Return Value

Type: String

isCurrentUserLicensed(namespace)

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

Signature

public static Boolean isCurrentUserLicensed(String namespace)

Parameters

namespace
Type: String

Return Value

Type: Boolean

Usage

A TypeException is thrown if namespace is an invalid parameter.

isMultiCurrencyOrganization()

Specifies whether the organization uses multiple currencies.

Signature

public static Boolean isMultiCurrencyOrganization()

Return Value

Type: Boolean

© Copyright 2000–2014 salesforce.com, inc. All rights reserved.
Various trademarks held by their respective owners.