What is the best way to prepopulate the lead phone field or any field on the standard lead creation page?

I currently have a link on a visualforce page to open the lead creation page, but URL hacking does not seem like a stable solution as the ID of the field will change as I cascade this through orgs correct?

I looked into quick actions as well, but that seems irrelevant.

Another solution that has come to mind is to use an onClick() on my link to invoke the console tab method to open a primary tab of the lead page, add event listener for when the page has loaded, then use some JS parsing/filtering to select the ID, but that sounds too convoluted for what I am trying to accomplish and I am wondering if there is a better way?

More Info:

I would ideally like to create the lead through the standard lead creation UI populating a few of the fields with dynamic values on Salesforce Classic in the Salesforce Console.

  • How lead is created? from UI? or API? Aug 6, 2018 at 17:26
  • From UI... I would just like to populate one or two of the fields before filling out the rest in the UI.
    – S.B.
    Aug 6, 2018 at 17:27
  • Do you want to populate static values ? Or it should be dynamic values ? Aug 6, 2018 at 17:28
  • It's a dynamic value, which is currently being stored in a JS variable on that page.
    – S.B.
    Aug 6, 2018 at 17:29
  • Are you on classic or lightning?? Aug 6, 2018 at 17:30

2 Answers 2


OOTB fields on standard object layouts have id values that are not sensitive to orgs. A handy reference

so, if you are only going to do OOTB fields and given that you are going the URL hacking route, for Lead.Phone, use &lea8=18885551212 in the param string.

For custom fields, what I've done is override the New button with a visualforce page that uses fieldsets to display the fields you want to show on a new Lead. The controller can prepopulate the fields as follows

public Lead l { 
  get {
   if (l == null) {
     l = new Lead(fieldA = 'defaultA', fieldB = 'defaultB, ...);
   return l;

where on your VF page, you use {!l.xxx} notation to reference a field

Now, I'll admit, you have to maintain a VF page and if fields are added to the object, you have to remember to add them to the fieldsets.

However, the advantage of this approach is you can tailor the new Lead form to be the minimum fields needed to enter a Lead and organize them in a way that is optimal for new leads versus the page layout that might be optimized for edit/view

  • Thanks, I appreciate the link and solution, but any other ideas to include the setting of custom fields as well?
    – S.B.
    Aug 6, 2018 at 20:26
  • 1
    @sb -- ah right -- see edits above; url hacking for custom field IDs has no good solution
    – cropredy
    Aug 6, 2018 at 21:14
  • Thanks, this is definitely a solution, but I'm going to let this sit overnight and see if there are any other solutions where I'm not creating a new VFP. If not, I'll mark this as the answer. Thank you!
    – S.B.
    Aug 6, 2018 at 22:39

What I eventually worked out (and personally liked the best):

  • Display inputText components in a modal.

  • Button to open modal had onClick that passed the phone number into
    one of the inputText components by class name.

  • After inputText components were filled out, user clicks a command
    button that references a method on the class to insert the lead.
    onClick added to command button to use console tab method to open the newly created lead.

Code relevant to this question:

<apex:inputText styleClass="phoneFieldClass"/>

<div id="modal">
     <apex:inputText styleClass="phoneFieldClassLeadModal"/>

     var fieldForPhonePass = document.getElementsByClassName('phoneFieldClass')[0];
     var fieldForPhoneReceive = document.getElementsByClassName('phoneFieldClassLeadModal')[0];
     fieldForPhoneReceive.value = fieldForPhonePass.value;

You must log in to answer this question.

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