Newer Version Available
UserInfo Class
Namespace
UserInfo Methods
The following are methods for UserInfo. All methods are static.
getDefaultCurrency()
Signature
public static String getDefaultCurrency()
Return Value
Type: String
Usage
getFirstName()
Signature
public static String getFirstName()
Return Value
Type: String
getLanguage()
Signature
public static String getLanguage()
Return Value
Type: String
getLastName()
Signature
public static String getLastName()
Return Value
Type: String
getLocale()
Signature
public static String getLocale()
Return Value
Type: String
Example
1String result = UserInfo.getLocale();
2System.assertEquals('en_US', result);getName()
Signature
public static String getName()
Return Value
Type: String
Usage
The format is one of the following:
- FirstName LastName
- LastName, FirstName
getOrganizationId()
Signature
public static String getOrganizationId()
Return Value
Type: String
getOrganizationName()
Signature
public static String getOrganizationName()
Return Value
Type: String
getProfileId()
Signature
public static String getProfileId()
Return Value
Type: String
getSessionId()
Signature
public static String getSessionId()
Return Value
Type: String
Usage
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.
getTimeZone()
Signature
public static System.TimeZone getTimeZone()
Return Value
Type: System.TimeZone
Example
1TimeZone tz =
2 UserInfo.getTimeZone();
3System.debug(
4 'Display name: ' +
5 tz.getDisplayName());
6System.debug(
7 'ID: ' +
8 tz.getID());getUiTheme()
Signature
public static String getUiTheme()
Return Value
Type: String
The preferred theme for the current user.
- 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
- Webstore—Salesforce AppExchange theme
getUiThemeDisplayed()
Signature
public static String getUiThemeDisplayed()
Return Value
Type: String
The theme being displayed for the current user
- 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
- Webstore—Salesforce AppExchange theme
getUserEmail()
Signature
public static String getUserEmail()
Return Value
Type: String
Example
1String emailAddress =
2 UserInfo.getUserEmail();
3System.debug(
4 'Email address: ' +
5 emailAddress);getUserName()
Signature
public static String getUserName()
Return Value
Type: String
getUserRoleId()
Signature
public static String getUserRoleId()
Return Value
Type: String
getUserType()
Signature
public static String getUserType()
Return Value
Type: String
isCurrentUserLicensed(namespace)
isMultiCurrencyOrganization()
Signature
public static Boolean isMultiCurrencyOrganization()
Return Value
Type: Boolean