+ Start a Discussion

How do I create a lookup field in S-control

I want to create an S-control form where one of the fields is supposed to be a lookup field - e.g I want to define a field called "Contact" and be able to have the lookup icon.
When clicked it should show all salesforce contacts and when one is selected, populate it.

How do I do it?

This is wickedly annoying to do, but here goes...
  <script src="/static/022207/js/functions.js"></script>
  <link rel="stylesheet" href="/dCSS/Theme2/en/common.css">
  // all your code will go here.
<form name="theForm" id="theForm">
<tr><td class="labelCol">
<label for="contact">Contact</label>
<input type="hidden" name="contact_lkid" id="contact_lkid">
<input type="hidden" name="contact_lkoid" id="contact_lkoid">
<input type="hidden" name="contact_lktp" id="contact_lktp" value="003">
<input type="hidden" name="contact_lspf" id="contact_lspf" value="0">
<input type="hidden" name="contact_mod" id="contact_mod" value="0">
<td class="dataCol">
 <span class="lookupinput">
  <input type="text" id="contact" name="contact"
  <a title="Related To Contact Lookup (New Window)"
   id="whtbtn"><img src="/s.gif" alt="Related To Contact Lookup (New Window)" class="lookupPopup"></a></span></td></tr>

And... yes, that's for a single lookup, and I don't even have all the required elements to make it look "Salesforce-like", just close enough to give you a text box and a magnifying glass. This whole magick code could break at any time; VisualForce is the only "guaranteed" method of not breaking lookup elements inbetween releases. So, enjoy the code, and have fun.
Edit: Fixed code that would have likely produced incorrect results. The "src" button is getting better though.

Message Edited by sfdcfox on 12-24-2007 03:48 PM
The &colon; in the above code should probably be an actual colon, but it's encoding it for me, probably a XSS feature.
Hi there,
what if i wanted to do the same thing - but in an s-control accessed by a button on a page. For example  - I would like to pre-populate the contact related lookup on the opportunity page.
so i created a button accessing an s-control, and my s-control looks like this

<script language="JavaScript">

function redirect() {


00N20000000vVQR={!Contact.FirstName}+{!Contact.LastName}&CF00N20000000vVQR_lkid={!Contact.Id}& CF00N20000000vVQR_lkoid={!Contact.Id}& CF00N20000000vVQR_lkold={!Contact.Id}& &CF00N20000000vVQR_lktp={!Contact.Id}& CF00N20000000vVQR_lspf= {!Contact.Id} & CF00N20000000vVQR_mod={!Contact.Id}&CF00N20000000vVQR_lkwgt={!Contact.Id}&accid={!Account.Id}&opp3={!Contact.FirstName} {!Contact.LastName} Follow Up- {!Today}&opp9={!Today}")




it is still not populating though - any ideas?
I have pre-populated a contact lookup on a custom related object - does this have to do with the opportunity role setup?
Thanks sfdcfox.

Does you know when VisualForce might GA?