I am trying to get the native lookup window to open up and when the value is selected needs to populate a hidden field.

I am able to call the lookup function, but when i select the value nothing happens, the lookup window doesnt close and value is not posted into the hidden field.

function showLookup(ctrlID,objKeyPrefix) 
        openLookup("/_ui/common/data/LookupPage?lkfm=ConvertwithInputs:pbmconvertInput:pbformmconvertInput&lknm="+ ctrlID +"&lktp="+objKeyPrefix,500);           

<apex:inputText id="vField_AccountName_lkid" value="{!s.selectedAccount}"/>           
<apex:image url="/s.gif" alt="Lookup (New Window)" styleClass="lookupIcon" onmouseout="this.className = 'lookupIcon';this.className = 'lookupIcon';" onmouseover="this.className = 'lookupIconOn';this.className = 'lookupIconOn';" onclick="javascript:showLookup('ConvertwithInputs:pbmconvertInput:pbformmconvertInput:pbsmconvertInput:pbspbtable:' + jQuery(this).closest('tr').prevAll('tr').length + ':vField_AccountName','001')" title="Lookup (New Window)"/>

The url generated in the lookup used by the above window is


The url when you click on search result is


To test the urls i also had a standard lookup and the url generated is


The link on the search result for standard lookup is


Where does the closing of lookup window happen?

Any pointers on what is happening while clicking of search result, where does the closing and assigning of value happen?


  • 1
    The official answer is, of course, that you should not try to use the built-in libraries, because they could change in a future release that breaks your page(s). Personally, I'd build my own, just so I know how it works.
    – sfdcfox
    Commented Sep 11, 2013 at 11:28

3 Answers 3


As sfdcfox stated, not a good idea to use the SF libraries.

Here is a link to a blog post by Jeff D. that works well for roll your own Salesforce lookup popup window:

It’s a handy little button that pops up whenever you need to search for related records. It does a pretty good job but it has some serious drawbacks:

  1. It’s virtually impossible to modify your search criteria. What if you want your users to do some crazy search based upon custom logic or search a field that is not typically available? Sorry… you are out of luck. Not possible.
  2. It’s terrible for creating new records. Let’s say that a user searches for a specific related record and it (absolutely) doesn’t exist. To create the new record they need to close the lookup window, navigate to the tab to create the new related record, create the new record, then go back to the original record they were either editing or creating, pop up the lookup window again and find their newly created record. Wow! That’s a lot of work.
  3. “Quick Create” is evil! You can enable the “Quick Create” option for an entire org but don’t do it! It displays, by default, on the tab home pages for leads, accounts, contacts, forecasts, and opportunities! The major problems are that you can only create new records for these 5 objects (what about the other ones!?), you can’t customize the fields on the page and validation rules don’t fire (can you say, “bad data”).



I experienced this issue when trying to call the native Lookup window through a custom button as part of some work with Campaigns. I had the behavior set to URL, and this was causing the lookup window to open, but never close whenever a value was selected.

The URL in my custom button was set to: /_ui/common/data/LookupPage?lkpr=00vf0000004Sh6f&lktp=701&enableScopes=1&addToCampaign=1&isCMClone=1

To get around this, it appears that Salesforce accepts an openLookup JavaScript function.

Therefore, I changed the expected behavior to JavaScript on my custom button, and put in the following code, which then allowed the Lookup Window to close whenever a value was selected.


(This button applies to Campaigns/Campaign Members, so you likely don't need all the parameters.)


have you checked your Javascript console, I think that the onlick for the searchResult fails

<a href="#" class=" dataCell " onclick="top.window.opener.lookupPick('editPage','acc3_lkid','acc3','','001i0000008NgRR','SW_Sample Customer','null','')">SW_Sample Customer</a>

And I think thats because the lookupPick and functios called from it try to access one of the other lookup related fields

<input type="hidden" name="acc3_lkid" id="acc3_lkid" value="000000000000000">
<input type="hidden" name="acc3_lkold" id="acc3_lkold" value="null">
<input type="hidden" name="acc3_lktp" id="acc3_lktp" value="001">
<input type="hidden" name="acc3_lspf" id="acc3_lspf" value="0">
<input type="hidden" name="acc3_lspfsub" id="acc3_lspfsub" value="0">
<input type="hidden" name="acc3_mod" id="acc3_mod" value="0">

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .