Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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>

 </apex:page>

Please guide me how do get the user ID.

share|improve this question

2 Answers 2

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 at 10:19
    
Then @Bachovski's answer would fit in. –  codebandit Apr 9 at 10:20
    
Nice catch @codebandit! –  Bachovski Apr 9 at 10:41

Your Answer

 
discard

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.