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
MubashirMubashir 

How to input lookup field in VF form

Referring to Developer Trail - Beginner: Inputting Data Using Forms, is it possible to have an lookup input field with the search icon giving ability to choose one from the list of existing records instead of creating a new one. e.g. <apex:inputField value="{! Contact.Account.Name}"/> renders the label and blank space for Account field for this Contact.

thanks
Best Answer chosen by Mubashir
NagaNaga (Salesforce Developers) 
Hi Mubashir,

Please see the sample code below


 Every LookUp field store Id of the related object's record and its string type.

Thatswhy we use "accountid".

So,use this  <apex:inputfield value="{!opportunity.accountid}"/>.

If we want to access any lookup field in visualforce page,use id with field as mentioned above.

Please see the link below

https://developer.salesforce.com/forums/?id=906F0000000Af5WIAS

Best Regards
Naga Kiran

All Answers

NagaNaga (Salesforce Developers) 
Hi Mubashir,

Please see the sample code below


 Every LookUp field store Id of the related object's record and its string type.

Thatswhy we use "accountid".

So,use this  <apex:inputfield value="{!opportunity.accountid}"/>.

If we want to access any lookup field in visualforce page,use id with field as mentioned above.

Please see the link below

https://developer.salesforce.com/forums/?id=906F0000000Af5WIAS

Best Regards
Naga Kiran
This was selected as the best answer
William TranWilliam Tran
so for your specific example of contact.account use this:

        <apex:InputField value="{!contact.accountid}" />

Thx
Prabhat Kumar12Prabhat Kumar12
You use  this code this will display level and search icon as well. 
 
<apex:page standardController="Contact">
  <Apex:PageBlock>
  <apex:pageBlockSection>
  <apex:form >
  <apex:outputLabel value="Accounts" for="acc"/>
  <apex:InputField value="{!Contact.Accountid}" id = "acc"/>
  </apex:form>
  </apex:pageBlockSection>
  </Apex:PageBlock>

</apex:page>

 
MubashirMubashir
Smashing!
thank you all.