I've a created a custom button on Contact object and added this to Contact Related-list on Account's Page layout. I want this to depict same functionality as standard "New Contact" button does. If use following code then it doesn't pre-populate the Account lookup field.


Is there any way to do so?

2 Answers 2


Try using

window.open('{!URLFOR($Action.Contact.NewContact, Contact.Id )}');

Update : try this : click on inspect element on the lookup button and you can find Id of the lookup as con4_lkwgt (I would assume this to be same since its a standard field) and click on the account name field and get the ID as con4


Refer this blog for more insight on how to override the buttons http://raydehler.com/cloud/clod/salesforce-url-hacking-to-prepopulate-fields-on-a-standard-page-layout.html

  • have you tried above thing?
    – doga
    Nov 20, 2012 at 8:06
  • ah i am sorry I actually was working on this never knew i posted,I will try to post ans shortly
    – Rao
    Nov 20, 2012 at 8:11
  • try this : create a button with URL : /003/e?con4={!Account.Name}&con4_lkwgt={!Account.Id}&&retURL=/{!Account.Id} the con4 corresponds to the account name and th con4_lkwgt corresponds to the lookup!! I tried and was able to create a record with account prepopulated :)
    – Rao
    Nov 20, 2012 at 8:14
  • 1
    @rao - minor thing. Form prepopulation is done by name attribute of <input> etc, not by id. Luckily we're quite safe in SF world but you know, in case you ever need to craft an URL to other system... Run this one and you'll see: translate.google.com/?source=id_works&text=no,name_works_better :)
    – eyescream
    Nov 20, 2012 at 9:20
  • 1
    @rao It's been a while since I wrote HTML forms by hand... If I recall correctly duplicate names mean last value will "win" so it will be overwritten in the order in which they appear in form. There's one exception: name="myVariable[]" with brackets. It's used if you want to pass multiple values to the server (think "3 out of 5 checkboxes ticked" or <select> tag with multiple options (ctrl+click)). stackoverflow.com/questions/4631224/…
    – eyescream
    Nov 20, 2012 at 15:27

You'll have to look at the field names. The list of names for standard fields is for example here: http://phollaio.tumblr.com/post/22058016777/how-to-obtain-a-field-id, for custom fields it's usually the field Id when viewed in setup (in case of doubt use Firebug or similar tool to inspect the HTML).

Something like this should give you the general idea how to start:


It's up to you if you want to write full URL yourself or do you prefer to read a bit more about URLFOR function (quite powerful). Generally speaking this will populate Account nicely if you've fired it from rel. list under Account - from other places it is likely to return empty string so you might have to use CASE() or similar to make it more generic (depends on when do you plan to use the button).

  • if I have custom object instead of Contact object which is also having lookup to Account then it will also work?
    – doga
    Nov 20, 2012 at 8:08
  • doga it does but in the con4_lkid replace it with the corresponding field Id for account lookup on the custom object where the account lookup is created
    – Rao
    Nov 20, 2012 at 8:25

You must log in to answer this question.

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