How do I display an input field for Users, in a visualforce page?

salesforce, visualforce

Solution

`OwnerId` field should be writeable. Unless your field security permissions are messed up or for example the field is hidden because it's a detail in Master-Detail relationship.

But when you'll manage to get it to work you'll see that most likely it's a bit weird lookup that can point to User or Queue.

If you're fine with that - great, just check the security around the field. If you need really only a lookup to user - check if you have any custom `Lookup(User)` field? You could create a dummy record of that type in the controller and don't do any DML with it, just use the fact it'll have the lookup.

If you don't have any custom ones - I think that Account / Contact / Opportunity owner must be a user (can't have queues). You might have to force `<apex:input field... required="false"/>` but other than that it should OK?

Problem

I simply want to display an input field, that will let me capture a user, so I can filter a list from a custom object by owner. CustomObject__c.OwnerId is not writable, so when I bind it to an input field, nothing is displayed on my page! I don't want to have a drop down list of users (There could be hundreds!) and I don't want to create a spurious custom object with a writeable field, related to the User object. How can I get the input field functionality for a read only field, as if it were writeable?

Original source