Role name and Profile Name from User Object using SOQL

How to get the Role name and Profile Name from User Object using SOQL

We can get the Role Name and Profile Name details from User Standard Object for the current context

SOQL Query:
SELECT Profile.Name, UserRole.Name FROM User

Below is the code to retrieve the User Role Name and Profile Name based on the logged in user in Apex Class

Apex Class:

Id userId = userinfo.getUserId();
User userDetails =[SELECT Id, Name, Email, Profile.Name, UserRole.Name FROM User
where Id=:userId ];
system.debug('Profile Name:'+ userDetails.Profile.Name);
system.debug('Role Name:'+ userDetails.UserRole.Name);

 

Advertisements

One comment

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s