I want the User Id to be displayed in a visualforce page

 public class getUser{

   public void classGetID()
     String s=UserInfo.getUserId();

Following is my visualforce page..

 <apex:page Controller="getUser" >

    <apex:outputText value="!classGetID"></apex:outputText>


Please guide me how do get the user ID.

2 Answers 2


First, You need to return the Id in your method (your method is void which means it won't return anything if you call it) - like this:

public Id classGetId()
    return Userinfo.getUserId();

Then in your page you need to call this method (your syntax is not correct) like:

<apex:outputText value="{!classGetID}"></apex:outputText>

You can use the User global variable, which would be quite straight forward

 <apex:outputText value=" {!$User.Id}"/>   
  • Thanks for the info, but I was learning to call methods into visualforce.
    – MnZ
    Apr 9, 2014 at 10:19
  • Then @Bachovski's answer would fit in.
    – codebandit
    Apr 9, 2014 at 10:20
  • Nice catch @codebandit! Apr 9, 2014 at 10:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .