How to get the current User Profile in Apex Class?

What is the right way to get the current users profile in an apex class?

When I tried to print the following in visualforce page, i am able to get the profile name

<apex:outputText value="{!$Profile.Name}"/> 

But when i tried to print in the Apex class using System.debug(Profile.Name), I couldn’t.


Id profileId=userinfo.getProfileId();
String profileName=[Select Id,Name from Profile where Id=:profileId].Name;

Refer the above code

Source : Link , Question Author : Arun , Answer Author : Mohith Shrivastava

Leave a Comment