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

Populating Lookup field on LEADS object using Web To Lead or Web Form.

Hi there,

We have a lookup field on LEADS point to Accounts. The Web To Lead Form does not display the Lookup field called "Reseller", and I am not sure what HTML element should be used to grab the data from the Web Form and then populate into the look up field into LEADS object.

We have tried using something like this:-




Reseller:<input  id="00N80000004nbGG" maxlength="100" name="00N80000004nbGG" size="20" type="text" /><br>

This is not working.

On the Web Form the field Reseller is a picklist while in SFDC we are trying to populate into lookup field.

How should this be resolve, what do we need to do on our web form to populate this value into SFDC under the lookup field.?


In case you are still looking for a solution (and have the ability to write triggers), try the following:


1) Create a new Text field on the Lead object. Call it "Reseller Text" (or whatever you'd like). Write down the id of this field.


2) On your form update the input attributes as follows:




this can be any value you want ('reseller-text' below). Salesforce does not care what value you put here (and, if you want your form to be W3C compliant, you dont want to start an id with a number).




enter the id of the "Reseller Text" field you just created. ('00N400000012abc' below).




this is the value you want to populate in the "Reseller" lookup field. ('00N800000045def' below).


Reseller: <input  id="reseller-text" maxlength="100" name="00N400000012abc" value="00N800000045def" size="20" type="text" /><br>


3) Create a trigger to copy the value of the "Reseller Text" field to the "Reseller" lookup field. Your trigger may look something like this:


trigger updateReseller on Lead (before insert) { 
        if (newLead.Reseller_Text__c!=null) {             
            String resellerString = newLead.Reseller_Text__c;            
            Id resellerID = resellerString;            
            newLead.Reseller__c = resellerID;       


Note that this does not give your form the ability to perform a "lookup"- it just allows you to populate the Salesforce lookup field with a hard-coded value.


You could very easily change the <input> to a <select> field to populate the lookup field with any number of hard-coded values.


Good luck!


Thank you so much for this.  I had figured out Steps 1 & 2, but couldn't figure out the trigger (having discovered that I could not directly populate the ID to the look up field).  This did the trick for me!
Noah TruaxNoah Truax
I tried to use what Captain Obvious said, and I got the following error: 

"Salesforce could not create this lead because of the reason listed below. For more information about this error or help with Web-to-Case-Lead, please contact Customer Support.
Reason: Apex trigger updatex1st_Dog_s_Breed caused an unexpected exception, contact your administrator: updatex1st_Dog_s_Breed: execution of BeforeInsert
caused by: System.StringException: Invalid id: Xoloitzcuintli: Trigger.updatex1st_Dog_s_Breed: line 9, column 1
    Lead Capture Page:
Record Information:
    00N1500000E7GOx = Quixote
    00N1500000E7mKi = Xoloitzcuintli
    city = Test City
    email =
    encoding = UTF-8
    encoding = UTF-8
    first_name = John
    last_name = Sample
    lead_source = direct mail
    oid = 00D15000000FylG
    retURL =
    state = Ca
    street = 555 Address Lane
    submit = Submit
    zip = 55318
To incorporate this lead into you can key in the data above.
If you have any questions, please click on Support at the top right of any page within
Customer Support"

I am trying to use a web-to-lead form to capture a fixed set of values from a picklist, except I really want that to populate a custom object that I have linked to my lead records via a custom look-up field.  Here is the code I tried to use:

trigger updatex1st_Dog_s_Breed on Lead (before insert) {
        if (newLead.Dog_Breed__c!=null) {            
            String x1st_dog_s_breedString = newLead.Dog_Breed__c;           
            Id x1st_dog_s_breedID = dog_breedString;           
            newLead.Dog_Breed__c = x1st_dog_s_breedID;      

Can you tell me where I went wrong?
Talha SaqibTalha Saqib
You can use custom lookup field in the web-to-lead form by following the guide below:
Talha SaqibTalha Saqib
You use custom lookup field in the web-to-lead form by following the guide below: