function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Gaston LeferGaston Lefer 

How do you use the code below to retrieve the current userid

1var userId =$A.get("$SObjectType.CurrentUser.Id");
2Console.log(userId);
Aslam ChaudharyAslam Chaudhary
var userId ="{!$User.Id}";

Hope this helps, Mark this as a best answer if you feel. 
Gaston LeferGaston Lefer
No that code for the lightning controller how to I display the user info on the component itself?
Stas ChristiansenStas Christiansen
Hey Gaston, 

You'll first have to set an attribute in your component like so: 
<aura:attribute name="userId" type="String" />

Then in your actual controller/helper method you will need to set the attribute we have in the component(named userId) to the value which you have stored in the userId variable, like so: 
 
var userId = $A.get("$SObjectType.CurrentUser.Id");
component.set('userId', userId);

Then, back in your component you can now display the attribute variable like so:
 
{!v.userId}

 Let me know if that answers your question!
 
Gaston LeferGaston Lefer
var userId = $A.get("$SObjectType.CurrentUser.Id"); component.set('userId', userId);

This goes in the doinit function? where?
Gaston LeferGaston Lefer
why dont you have "Console.log(userId);"