Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 3 down vote accepted

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>
share|improve this answer

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

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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.