You need to sign in to do that
Don't have an account?
RCJesse
Getting User object field in VisualForce controller
I have a VF page with matching controller to make some links for our reps. I want to append the value from the last name field from the running user's User object to my link. In my controller i have the main url hardcoded as a string and then i add parameters to that string depending on the field values. But when if i do something like
link = link + 'spid=' + User.LastName;
What I actually get is "spid=LastName"
If i try to add the value as a apex:param to a link the code "%3f" shows up where it should have an "&".
Definitely, for that you just use the getUserId() method and query for any fields based on the user id...
String myCustomField = [select Id, myCustomField__c from User where Id=:UserInfo.getUserId() limit 1].myCustomField__c;
All Answers
Hello Jesse;
Don't u like this kind of a solution?
link = link + 'spid=' + Userinfo.getLastName();
If possible, I recommend having your controller return PageReference instances instead of a text URL. You can then add the Last Name as a parameter like so:
myPageReference.getParameters().put('spid', UserInfo.getLastName());
It will then make sure the characters are URL friendly... and then you don't have to worry about doing any client side redirects.
Just my two lincolns, in case it helps.
Definitely, for that you just use the getUserId() method and query for any fields based on the user id...
String myCustomField = [select Id, myCustomField__c from User where Id=:UserInfo.getUserId() limit 1].myCustomField__c;