You need to sign in to do that
Don't have an account?
Isaac Gomolka
Lookup Field for Users on Visualforce Page
Hi, I was wondering how to get a Lookup field for Users onto a visualforce page. I tried finding something on this, but nobody uses it with Users, they use accounts or opportunities. I want to be able to have an inputField with the lookup button thing next to it so whoever is using my visualforce page can click on it and lookup a User that we have in Salesforce and select it. If you could also help explain how I would then be able to pull information from the user selected, thatd be a great help. By that i mean like I'm supposed to be copying information of a User that someone inputs to use to create a new user. Any help or explanations would be very very helpful. Thanks!!!
Normally we user apex:input field to bind the field so that type of field automatically reflected on page, howver if you want to create a lookup to user then you can create reference for a field where lookup to user exist, I am taking the example of Manager field on user object, manager field is lookup to user on user object.
Here usr is type of get set so the value selected from the page will be reflected in usr.ManagerId field, you can pull additional information on basis of it.
For more detail use this : https://developer.salesforce.com/forums/?id=906F000000094YKIAY
Mark answer as solved if it does help you.
Yes that should be the lookup field, if you open in classic then could see magnifying glass picture while in lightning it is bit different.
Thanks,
Rahul
So I guess it does bring up the magnifying glass and makes it a lookup field. I was trying it with a different field then ManagerID. Why does it only work for some fields and not others? And if you know, if I, say, set it to ManagerId and lookup a User and select it. Is there a way to store that User? In the sense that like I need that whoever is using the page to use that lookupfield to select a User, and then in my apex code or whatever use many fields and things from that looked up user. For example, if i look up the name Matt Smith and select it, in my code is there a way to use like usr.OtherFields and get info from Matt Smith's User information besides the ManagerID(or whatever the lookup field refers to)?
Thanks again for your help! I really appreciate it.
-Isaac
It will work for only the fields which are of lookup to user type, ultimatly we are using lookup from a field a same type, also whatever the you will select here will get bind to apex veriable usr which is of type get; set;, you can further utilize the value using usr.Manager, it will return the id of the selected user.
Mark solved if it does help you
When I try using usr.Field(field being any field besides ManagerID) it doesn't return anything. However when i do use usr.ManagerID it does return the ID of the user selected. Do you know how I would be able to get all the other information from that selected user? Pardon me again im not very good at Salesforce yet, this is my first semi-big project I've been put on as an intern. If i had to guess I would assume I would need some kind of SOQL statement or something that searches Users using the ID given to me from the inputfield, and assign that user to a user variable so I can get any of their fields. Would this be correct? And if so would you have any idea what that SOQL statement would be? Can't thank you enough for all the help!!!
Thanks,
Isaac