Pre-populate Fields Using URL Parameters

For my example I am going to pre-populate some fields on the contacts object. Now the contacts object (like all salesforce objects) has what salesforce sometimes refers to as a front door for the URL. Quite simply the front door for the contacts tab is "/003/o". The front door for a new contact would be "/003/e". If you want to see what the front door is for any object simply click the tab for the object. The front door is the three characters directly following the ".salesforce.com/" portion of the URL while you are on the tab's "home" screen. Further examples; Opportunities home is "/006/o", Accounts home is "/001/o". If you want to add a new record for the object you simply change the "o" portion of the front door to an "e". I know I wrote that the front door was three characters but I think you get my drift here.

So now what? Well, if you need to pass information to a new record (regardless of custom or standard object) you simply add additional parameters to the URL following the front door portion of the string. Each parameter must be separated by an ampersand (&) except for the first parameter which must use a question mark (?). To find out what parameters can be sent in the URL for your object you can either use Firefox with a developer plug-in to view the form details on the edit screen of your object or you can use any browser and simply view the source code of the edit screen. Each editable field on the screen has an id and a name. For example on the contacts edit screen the salutation field part of the form has the name and id of "name_salutationcon2".

Using this information we can now add a new contact using nothing more than parameters passed in the URL. To finish my example I am going to pre-populate a new contact record with a first name, last name, salutation, email address and description. Please note that since we are passing parameters using the URL any special characters you want to use in a value field will need to be encoded so that they can be properly interpreted by the browser. A good reference for url encoding is W3Schools.

Breakdown of URL:

  • Front Door for new contact record: /003/e
  • Salutation for new contact: ?name_salutationcon2=Ms%2e (question mark is to denote that this is the first parameter in the URL; “%2e” is the encoded value for a period “.”)
  • First Name for new contact: &name_firstcon2=Tess (ampersand “&” separates this parameter from the first parameter; “name_firstcon2″ is the form id for the first name; equal sign “=” separates the form id from the form value; “Tess” is the value that I want the first name to be)
  • Last Name for new contact: &name_lastcon2=Dachshund
  • Email for new contact: &con15=greg%40interactiveties%2ecom (jumbled because of encoding)
  • Description for new contact: &con20=I%20like%20my%20dog (jumbled because of encoding)

Putting it all together:

https://na2.salesforce.com/003/e?name_salutationcon2=Ms%2e&name_firstcon2=Tess&name_lastcon2=Dachshund&con15=greg%40interactiveties%2ecom&con20=I%20like%20my%20dog

Hopefully, most people reading this are using contacts in their orgs and, therefore, should be able to cut and paste the string from my example into a browser and see exactly what I’m trying to illustrate.

Now there is a lot more that can be done using this information. You could add code similar to this to a custom button or custom link and use values from another object to pass in the URL to your new record (like apex generated values such as {!Opportunity.Id} to link your new record to a specific Opportunity). In addition there are some specific parameters that can be added to the URL (like “retURL”) to make the functionality more robust or even pass a specific parameter to save the new record without displaying the new record screen. However, the information contained in this post should be enough to at least get you pointed in the correct direction.

Automated Exchange Rates in Salesforce.com

Reduce Repetitive Tasks, Eliminate Errors & Free Up Your Administrators.

Birthday Reminders for Salesforce.com

It might lead to a sale. Or it might make you feel good.