You need to sign in to do that
Don't have an account?

Accessing User.FirstName in a Controller
Hi, I come from C# land and am new to Apex. I am simply trying to get access to the User.FirstName value in the controller. I can do this in the view just fine:
{!$User.FirstName}
Below are examples of my attempts at doing this...
// In the view:
// -----------------
{!test}
// In the controller:
// -----------------
// Compiler error: Return value must be of type: String
public static string test { get { return User.FirstName; } }
// Compiler error: Incompatible types since an instance of Schema.SObjectField is never an instance of String
public static string test { get { return (string)User.FirstName; } }
// Compiles but always returns 'FirstName'
public static string test { get { return User.FirstName + ''; } }
// Compiler error: expecting a semi-colon, found ':'
public static string test { get { return :User.FirstName; } }
// Compiler error: line 33:10 no viable alternative at character '$'
public static string test { get { return $User.FirstName; } }
Surely there is a way to do this?
Thanks!
You can use
UserInfo.getName() , UserInfo.getFirstname() , Userinfo.getLastName();
All these ale User Info methods
You can use it like this in property
All Answers
You can use
UserInfo.getName() , UserInfo.getFirstname() , Userinfo.getLastName();
All these ale User Info methods
You can use it like this in property
I believe by using User.FirstName you are referring to Currently Logged in User's First Name.
If yes then, Try this :
SS - :P
What if we need to obtain the email which is present under $User.