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
indyinfyindyinfy 

How to add a Look Up field in VF page

I have a VF page whose standard controller is Contact . I have 3 fields First name, last name and Account Name. On click of Save I should be able to add a Contact with these 3 values. But how to add Account in the page which has to be a lookup field. Please help
 
Code:
<apex:page standardController="Contact">
<apex:Form>
<apex:pageBlock>Create New Contact</apex:pageBlock>
<p>First name: <apex:inputField value="{!contact.FirstName}"/></p>
<p>Last  name: <apex:inputField value="{!contact.LastName}"/></p>
<p>Account Name: <apex:inputField value="{!contact.accountid}"/></p>
<apex:commandButton action="{!save}" value="Save"/>
</apex:Form>
</apex:page>

 

 


Message Edited by Tran Man on 02-21-2008 10:48 AM
Manu ErwinManu Erwin
This exact code works for me.  The VisualForce page correctly interprets the accountid field as a lookup to the account and displays the lookup icon which when clicked pops the standard account lookup.

On save the contact is created.

Is your browser blocking popups?
indyinfyindyinfy

Thnx for the response Manu. But the same code does not work for me. The page it self does not show up. it gives an error on click of Save.

Unable to Access Page
Information needed by the page you have attempted to access is incorrect. If you believe this is an error, please refresh your screen. If the error persists, please report it to our Customer Support team and provide the URL of the page you were requesting as well as any other related information.

indyinfyindyinfy

Manu,

One thing I noticed. I directly copied the URL of the VF page and it worked fine.

But what I was trying to do earlier is I have overridden standard button "New" in Contact object and selected this VF page. Then it is not working.

Manu ErwinManu Erwin
So the page works fine if you access it directly? i.e., https://xx.salesforce.com/apex/<your_page_name>?

But does not display if you override the 'New' button?

Are you able to select your page when attempting to override the 'New' button? i.e., successfully override the button


Message Edited by manu on 02-05-2008 03:20 PM
jwetzlerjwetzler
Hi indyinfy.

You've hit a bug that we discovered about a week ago.  A page with an inputField lookup will work fine when accessed directly, but when used as a "New" override, it does not work.

This has been fixed and should be patched this weekend.  Apologies for the inconvenience.

Please let us know if you're still seeing this issue on Monday.

Thanks,
Jill
CTU007CTU007

Hi, it looks like this problem still exists: (in the following, LOA approval is on the detail side of a master-detail relationship to Opportunity)

when I access the VF page directly the inputfield is ok:

lookup field is ok

 

But after I click "quicksave", the field becomes read-only:

I also used this VF page to override the "New" and "edit" button, when user click "edit" button to edit an existing record, the field is also read-only:

 

field is read only

 

Is this supposed to be the way it should work? 

 

If I change to  the following, I got an error:

 

<apex:inputField value="{!LOA_Approval__c.OpportunityId}" /> Error: Could not resolve field 'OpportunityId' from <apex:inputField> value binding '{!LOA_Approval__c.OpportunityId}'