top of page
Search
HR

Expressway to Create Pre-Populated Records



Hello Fellas!!!

There are times when user wants to create record of one object from existing record of any other object. Seems like pretty easy requirement but time is a big constraint sometimes and it forces us to look into new and easy possibilities.

Well, I caught my client worried one fine day. He needed to create a lead record from existing contact record and populate some specific fields fetching it from contact. He also wanted to open it in edit mode, so that the user can modify the record if needed. As will be the first thought of many developers, Visualforce pages and standard controllers came in my mind. However, even before I could tell my client about what I was thinking, he told me that we don’t have much time so we need to rule out the option of custom development. And that is how I came across the idea of URL hacks. Believe me, it’s really handy!


You just have to follow these simple steps for the same:


Create Custom Link to Pre-populate fields on object

  1. Create new custom link/button on object and add it to the page layout. Go to your object and Click “New Button or Link” in the section Buttons, Links & Actions.

  2. Let’s give new button a name and select Detail Page Button. This means it can be placed on top of a record. We also want to make sure we have the behaviour set as the below and the content source as URL.

Create Custom Button/Link

3. Now to specify the object to be created or edited through this link mention the three letter prefix code of required object. You can find out your object code by creating a new record and looking at the first part of the URL. The “e” refers to edit, which means we are going to the edit page of this object. Here we are creating New Lead from existing Contact, so the value in URL field should be – /00Q/e

4. Now add field Ids of new object to be created (Lead in this case) and fields of existing object record (Contacts in this case) to be mapped in URL separated by ‘&’. /00Q/e?name_lastlea2={!Contact.LastName}&lea3={!Account.Name}


Create Field Mapping for Custom Link


For creating the field mapping, add key value pairs of fields as the parameters of URL separated by ‘&’. There are two ways of getting the field Id in field mapping for the custom link.

  1. Use Salesforce Field Id To get the ID of the field, go to the relevant object in setup and click on the field we wish to populate. If you check out the URL when you’re on this page, you can see the unique ID given to this field. E.g., /00N38000003I4GD?setupid=LeadFields Use this Id in URL to create mapping as given below: /00Q/e?00N38000003I4GD=&00N38000003I4GE=

  2. Use Field Id in HTML form Another way to get Id is HTML id of the field from object’s edit page layout. Follow the following setups to get the Id.

    1. Click on New button on object.

    2. Select the field for which the Id is required and right click on it to Inspect Element.

    3. You will get the id in input tag’s Id attribute.

Use Field Id in HTML Form


d. Use this Id to form the URL for new object creation. For example, /00Q/e?name_lastlea2={!Contact.LastName}&lea3={!Account.Name}


Pre-Populating Lookup Fields


To populate a Lookup value we need the field ID as before but this time we need to add “CF” to the front of the ID so it looks something like this – CF. This is required when you need to populate a custom lookup field.

  1. The first part to populate a lookup value is to grab the name of the record we are populating. So using the method before but with the added CF you can expect your custom link URL to look like this. /00Q/e?CF00N38000003I4GD={!Account.Name}

  2. The next step is to grab the ID of the record we wish to populate. This time though, we are going to add “_lkid” to the end of our field ID (plus the CF we added on earlier). This “lkid” parameter specifies that this is a lookup field. So it looks like this. /00Q/e?CF00N38000003I4GD={!Account.Name}&CF00Ni000000EpsgO_lkid={!Account.Id}

How It looks in Lightning?


As speaking of making above feature compatible with Salesforce lightning, it does not work the same. To achieve the above functionality we need to use “Quick Actions”. Let’s have a quick walkthrough of steps need to be taken for the same.

  1. Create new action on origin object, contact here

Create Quick Action in Lightning


2. Setup the fields for landing page.

3. Set predefined values for fields that you want to pre-populate. It will appear on quick action detail page once you are done with layout of fields.

4. Choose the field that you would like to pre populate. Formula Editor is used to provide the default value for that field. Define all the values that you require and save them. Et Voila!!! We are done. Go ahead and test your quick action in lightning view once you have added it to page layout.

Predefined Value for Field



Let me know how that works. Keep creating !!!



234 views0 comments

Comentarios


bottom of page