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
Jens Peter KristensenJens Peter Kristensen 

User lookup input field

Hi

I have a visualforce page with a apex controller connected. There is no connection / lookup to the user object.

On that page I need a <apex:inputField that has a standard lookup to the user object.

Right now my include field is not shown because I don't have it connected to a user object. 

Can someone tell me how to do this ?

Maybe it needs to be solved by creating a dummy field that has that lookup but I fail it getting it to work.

If somebody could help what is needed in the vfp and in the apex controller that would be great.

I tried to create a brand new vfp and apex controller to get a better understanding of the problem :

Vfp :

<apex:page controller="JpkTestController">
    <apex:form id="form">
    <apex:pageBlock title="View as" id="viewAs">
        <apex:pageBlockSection >    
               <apex:inputField id="TestUser" value="{!user1.Id}" required="false"/>       
         </apex:pageBlockSection>
    </apex:pageBlock>   
    </apex:form>
</apex:page>

Apx controller :

public class JpkTestController {

  public User user1 {get;set;}  

  public JpkTestController() {
        user1= new User(); 
  }
}
 
Paul_BoikoPaul_Boiko

You can use lookup field to user object on any object. And do something like this:
 
public class Controller {
    public Account acc {get;set;}
    
    public Controller(  ) {
        acc = new Account();
    }
}
 
<apex:page controller="Controller">
    <apex:form>
        <apex:pageBlock>
            <apex:pageBlockSection>
                <apex:pageBlockSectionItem>
                    <apex:outputLabel for="user">User</apex:outputLabel>
                    <apex:inputField id="user"  value="{!acc.User__c}"/>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 
Jens Peter KristensenJens Peter Kristensen
Hi Paul

I tried that and unfortunately it doesn't show my input field it only shows the label. Do you know why ?

No inputfield
Somebody told me it is because there was no relation to the user - but I don't understand what is missing 

Thanks a lot
Paul_BoikoPaul_Boiko
Check field level security for this field.