[SalesForce] Lookup window not closing after selecting the value in result

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

https://c.na15.visual.force.com/_ui/common/data/LookupPage?lkfm=ConvertwithInputs:pbmconvertInput:pbformmconvertInput&lknm=ConvertwithInputs:pbmconvertInput:pbformmconvertInput:pbsmconvertInput:pbspbtable:0:vField_AccountName&lktp=001

The url when you click on search result is

https://c.na15.visual.force.com/_ui/common/data/LookupResultsFrame?lktp=001&lknm=ConvertwithInputs%3ApbmconvertInput%3ApbformmconvertInput%3ApbsmconvertInput%3Apbspbtable%3A0%3AvField_AccountName&lkfm=ConvertwithInputs%3ApbmconvertInput%3ApbformmconvertInput#

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

https://c.na15.visual.force.com/_ui/common/data/LookupPage?lkfm=ConvertwithInputs%3ApbmconvertInput%3ApbformmconvertInput&lknm=massConvertwithInputs%3ApbmconvertInput%3ApbformmconvertInput%3ApbsmconvertInput%3Apbspbtable%3A0%3Aj_id7&lktp=001&lksrch=

The link on the search result for standard lookup is

https://c.na15.visual.force.com/_ui/common/data/LookupResultsFrame?lktp=001&lknm=ConvertwithInputs%3ApbmconvertInput%3ApbformmconvertInput%3ApbsmconvertInput%3Apbspbtable%3A0%3Aj_id7&lksrch=&lkfm=ConvertwithInputs%3ApbmconvertInput%3ApbformmconvertInput#

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?

Thanks

Best Answer

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”).

http://blog.jeffdouglas.com/2011/08/12/roll-your-own-salesforce-lookup-popup-window/

Related Topic