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
saurabh sharmasaurabh sharma 

How to add lookup of account on my vf page

Raj Jha 5Raj Jha 5
Hi Saurabh, 

Suppose you are working on Contact. on Contact, Account lookup is available. To show lookup on VF page 

public class ContactLookUpDemo
{
     public contact con{get;set;}
     public ContactLookUpDemo(){
            con = new contact();
     }
}


VF Page - 

<apex:page controller = "ContactLookUpDemo">
     <apex:form>
          <apex:pageblock>
                  <apex:pageblockSection>
                       <apex:inputfiled value="{!con.AccountId}" />
                </apex:pageblockSection>  
        </apex:pageblock>
    </apex:form>
</apex:page>


You need to use inputfiled in pagebliock section. 

Thanks,
-Raj


Vatsal KothariVatsal Kothari
Hi,
You can refer below code:

<apex:page standardController="Opportunity">
	<apex:form >
		<apex:inputField value="{!opportunity.AccountId}"/>        
	</apex:form>
</apex:page>

If this solves your problem, kindly mark it as the best answer.

Thanks,
Vatsal
jo devjo dev
hi Saurabh,

here i pasted the sample code using standard controller

sample code:

<apex:page standardController="Case">
<apex:form>
<apex:outputlabel value="Account Name:"> </apex:outputlabel>
<apex:inputfield value="{!case.Accountid}" style="width:160px"/>
</apex:form>
</apex:page>
Gaurav NirwalGaurav Nirwal
<apex:page controller = "ContactLookUpDemo">
     <apex:form>
          <apex:pageblock>
                  <apex:pageblockSection>
                       <apex:inputfiled value="{!con.AccountId}" />
                </apex:pageblockSection>  
        </apex:pageblock>
    </apex:form>
</apex:page>

Gaurav NirwalGaurav Nirwal
For the VF page You can use this code as above written by me this can solves your problem