URL Hack - Prepopulate Lookup Fields From Parent Data

Greetings Reader, laugh

In this post I will show you how to pre-populate data from the parent record when a child record is created from the related list. Some Geeky people may have already know this, but this is for Newbie people in Salesforce. So, Let's Started.

I will break the work into following parts:

1. Creating Field on Child Object.

2. Creating a Custom List Button.

3. Adding Custom Button  to the Parent Page Layout Related List.

1. Creating a Field on Child Object:

                In this post, I will use the example of Account and Contact (You can prefer any 2 objects with parent child relationshipyes). To create a lookup field in Contact object, Navigate to Setup -> Contact -> Fields  then Click on New button on Custom Fields. Select the type as "Look-Up relationship" Enter your field details and Save the field. (Dont forget to add the related list to parent layout wink , because this is where we will place our Custom Button cool)

                Now once the field is created, Copy the Salesforce ID of the field and keep it somewhere, this will be used in later part. The SF ID will look something like 00N280000068637.


2. Creating a Custom List Button :

              Create a New Custom Button by Navigating to Setup -> Contact -> Buttons,Links, and Actions. Click on New Button or Link.  If your are using Custom object, you may need to navigate Steup -> Create -> Objects -> Your Custom Object -> Buttons,Links, and Actions.

  • Give a name as New Contact.
  • Select Behavior as Display in existing window without sidebar or header.
  • Select Display Type as List Button.
  • Now enter the following in the URL body of the List Button  and Save the button:

                     /003/e?retURL={! Account.Id }&CF00N280000068637_lkid={!Account.Id}&CF00N280000068637={!Account.Name}

It will look like below screenshot

Let me break through the above line,

  1. 003 - this is the Sobject Type ID which is common for standard objects, but if you are using Custom object in your ORG, you can pretty easily take this by Navigating to Tab created for the object. When you click on the tab of a custom object , the URL will look something like "https://***.salesforce.com/a01/****".The highlighted will be your Sobject Type ID for the custom object.
  2. e? - This parameter is used to denote Saleforce that a new record is to be created for the Sobject Type 003 (which is contact in our case).
  3. retURL - This parameter will hold value for Return Address when user clicks Cancel button. You can use Merge Expressions to place id of return URL. In our case we need to go back to Account, hence we placed Account ID.
  4. CF ***** - This is where we do the prefilling of the fields. The CF  is  a Keyword that denotes it is a Custom Field. Now you need to construct the URL by placing CF followed by the Salesforce ID of the field that we took after creating the field. So when you add, it will look something like CF00N280000068637. Lookup ID always take 2 values : ID of the referred record and human readable text format to be displayed on the page.

         CF00N280000068637_lkid - You should assign ID of the record. In our case, Account ID

         CF00N280000068637 - You should assign Human readable text to be displayed on the input field box. In our case we assign account name.

3. Adding Custom Button  to the Parent Page Layout Related List:

        Go to Parent Page Layout , Click Edit. Navigate to the related list we added while creating the look up field on first step. Click on the Wrench icon to edit properties. Click on Button and add the Button we created to List and Save the layout.

If all goes correct when you create a record from the related list through the Custom list button, the field will be auto populated like shown below.

Now, You may have a question Can we do only for Lookup fields? The Answer is NO!! You can pre-populate any field like text , picklist etc; Pre filling these fields are easier than Lookups. You dont need to provide _lkid part for these fields. Why dont you give a try for a practice laugh.

P.S. Note:

1. The URL parameters are separated using '&'.

2. Don't leave any blank space while constructing URL. You will get URL No Longer Exists error.

Thank you for reading. Leave your thoughts and feedback in Comment section below. yes

Average: 5 (1 vote)