All about UserInfo Class in Apex

UserInfo class contains methods to get the LoggedIn User or Context User  information.

All methods in UserInfo class are static method, so you can access the methods using the syntax – ClassName.methodName() like UserInfo.methodName()

getUserId() Method – return the current user Id.

Id currentUserId = UserInfo.getUserId();

getProfileId() Method –  returns the current user profile Id.

Id userProfileId = UserInfo.getProfileId();

getUiTheme() method –  returns the preferred theme of the current user. Use getUiThemeDisplayed() to determine the theme actually displayed to the current user.

getUiThemeDisplayed() method – returns the theme displayed by the current user. Theme here means whether user is using Salesforce Classic or Lightning theme, using this you can identify current theme and do some business requirement.

String currentTheme = UserInfo.getUiThemeDisplayed();

Different them value are –

  • 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

getFirstName() – return the current user First Name of String type.

getLanguage() – returns the current user language of String type.

getLastName() – returns the current user Last Name of String type.

getUserName() – returns the current user login name of String type.

getUserRoleId() – returns the current user’s role Id of String Type.

getUserType() – returns the current user’s type of return type String.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s