Get current user information in apex
We can get current logged in user full information from predefined methods in apex.
***
// get current user id
String loggedUserId = UserInfo.getUserId();
// get current user name
String loggedUserName = UserInfo.getName();
// get current user username
String loggedUserUserName = UserInfo.getUserName();
// get current user email
String loggedUserEmail = UserInfo.getUserEmail();
// get current user language
String loggedUserLanguage = UserInfo.getLanguage();
// get current user profile id
String loggedUserProfileId = UserInfo.getProfileId();
// get current user role id
String loggedUserRoleId = UserInfo.getUserRoleId();
// get current user locale
String loggedUserLocale = UserInfo.getLocale();
System.debug('loggedUserId $$ ' + loggedUserId);
System.debug('loggedUserUserName $$ ' + loggedUserUserName);
System.debug('loggedUserName $$ ' + loggedUserName);
System.debug('loggedUserEmail $$ ' + loggedUserEmail);
System.debug('loggedUserLanguage $$ ' + loggedUserLanguage);
System.debug('loggedUserProfileId $$ ' + loggedUserProfileId);
System.debug('loggedUserRoleId $$ ' + loggedUserRoleId);
System.debug('loggedUserLocale $$ ' + loggedUserLocale);
Output :
***
Comments
Post a Comment