URL Hacking for Salesforce Automation

salesforce.com URL
Understanding the salesforce.com URL
June 1, 2015
salesforceiq
SalesforceIQ for Sales Cloud
October 27, 2015

URL Hacking for Salesforce Automation

url hacking
Applies to: Classic

In this post, we’ll explore how we can automate routine processes by creating custom button with URL. If you’ve not read my Understanding the salesforce.com URL post, be sure to review that post to learn some of the techniques we’ll use in this article.

Bypass the Select Record Type Page

The first example I’ll share will allow you to replace what the “Select Record Type” screen. This is the annoying Salesforce page that appears when you click the “New” record button on objects that have multiple record types. This screen can easily be replaced by creating a custom button. Let’s look at how:

I’ll assume you have already setup multiple record types on the Contact object (or object of your choosing). Complete the following steps to create a button to bypass the “Select Record Type” screen:

    1. Press the “New Contact” button from the Account’s Contact Related List
    2. The “Select a Record Type” screen will appear, so select the Record Type you want to automate and proceed to the Contact Edit page.
    3. Highlight and copy the URL on the new Contact Edit page.
    4. Navigate to Setup | Customize | Contact |Buttons, Link and Actions
    5. Press the “New Button or Link
    6. Give your Button a Label
    7. Select a Display Type of “Link Button
    8. Select the Behavior of “Display in existing window without sidebar or header
    9. Content Source should be “URL
    10. Paste the URL you copied from step 3 into the formula box. The formula should look something like this: (be sure to scroll to the right to see the entire url string)
      https://na11.salesforce.com/003/e?retURL=%2F001G000001p781C&accid=001G000001p781C&RecordType=012G00000014LM5&ent=Contact
    11. We now need to edit the URL to remove its domain portion of the URL. This will allow it to work on other domains such as your Sandbox org, making it what is called a “relative URL”. You should now have something like this: (be sure to scroll to the right to see the entire url string)
      /003/e?retURL=%2F001G000001p781C&accid=001G000001p781C&RecordType=012G00000014LM5&ent=Contact
    12. Next we need to replace the record IDs with merge fields with one exception.  You will leave the RecordType parameter as is. That ID (012G00000014LM5) represents the Record Type ID for the type of Contact you want to create.  Your formula should now look similar this: (be sure to scroll to the right to see the entire url string)
      /003/e?retURL={!Account.Id}&accid={!Account.Id}&RecordType=012G00000014LMA&ent=Contact
    13. Save the new button
    14. Edit the Account Page layout to add the new button to the Contact Related List and Save the page layout.
    15. Open an Account record and test the new button. If you competed all the steps correctly, you’ll be taken directly to a new Contact Edit page and the correct Record Type will have been automatically selected.
    16. Repeat the process for other Record Types.

This is a very simple technique to eliminate an extra click and the possibility of error.  Next we’ll look at using the same process to pre-fill fields on an Edit Page.

Pre-fill Fields on an Edit Page

In order to pre-fill the fields on a page, we will first need to identify the fields’ ID. This is the complex part but once you get used to this, it’ll become quite simple. Don’t let this piece intimidate you as I’ll show you multiple options to accomplish this. Once we have the field IDs, we’ll simply add them as additional parameters to our URL string; much like the example above.

Option 1:

Chrome: Use the Inspect Element feature
  1. Right click on the field
  2. Select Inspect Element
  3. Click the magnifier
  4. Hover over the field
  5. Its ID will be displayed
FireFox: Use Firebug
  1. Installed this Add-on and use it to find field IDs
Safari: User the Web Inspector
  1. Developer Menu
  2. Select Web Inspector
  3. Click on Inspect icon
  4. Hover over the field and
  5. Its ID will be displayed
Internet Explorer: Use the F12 Developer Tools
  1. Go to DOM Explorer
  2. Select element
  3. Click on the field
  4. Its ID will be displayed

Option 2: (works only on custom fields only)

Get the Field’s record Id from Setup:
  1. Click on the Setup link
  2. Click Customize or Create
  3. Click the Object Name
  4. Click Fields
  5. Click the field name
  6. Copy the Id from the URL

Option 3: (this is my least favorite method as you’re literally reading the page source code)

  1. From the Edit Page of the Salesforce record, select View Source code from the browser menu (the location of this option varies from browser to browser)
  2. Use your browser’s Search to Find the field’s Label (ie:  First Name)
  3. Look through the code to find the “Id” value

Once you’ve conquered the process above, the next step will be simple URL hacking.  We’ll create a New Button and modify the URL to accomplish our goal.  So copy the URL of the edit page you wish to pre-fill the data into. You’ll use that URL as your base to start with in your custom button.

  1. Complete the processes outlined in Steps 4 thru 12 from the above example
  2. Then edit the URL string to add new field using the format below:
    &[the field id]=[the field value you want auto filled]
Here’s a couple examples:

The example below creates a new Opportunity record and populates the Opportunity Name (opp3), Stage (opp11), Account (accid), Contact Role (conid), and a Custom Contact Lookup field (00NG000000EueOU): (be sure to scroll to the right to see the entire url string)

/006/e?retURL={!Contact.Id}&opp3={!Account.Name}-{!Today}&opp11=Prospecting&accid={!Account.Id}&conid={!Contact.Id}&CF00NG000000EueOU={!Contact.Name}&CF00NG000000EueOU_lkid={!Contact.Id}

In the above example, you’ll notice I’ve introduced a couple of new items:

  • First, because my Contact Lookup is a Custom Field, the field ID is prefaced with “CF”. I’m not sure what the rules are for when this is needed and when it isn’t but if the first attempt doesn’t work without it, add it and try again. Sometimes, that is the missing key between a URL that works and one that doesn’t.
  • Second, you’ll notice that I pass in the Contact data twice. The first time is the Contact’s name and the second is the Contact’s record ID. The record ID parameter includes that “_lkid”. For custom lookup fields, I’ve found that I need to use both of these parameters to get the expected results. For standard lookup fields, I only need to pass in the record ID.

This next example creates a new Task record and populates the Subject(tsk5), Contact (who_id), Status (tsk12), a custom picklist field (00NG000000EueOP), and Due Date (tsk4): (be sure to scroll to the right to see the entire url string)

/00T/e?title=Call&who_id={!Contact.Id}&tsk5=Call&tsk12=Completed&00NG000000EueOP=Left Message&tsk4={!Today}&retURL={!Contact.Id}

In this example, you can see we’re using a merge field for today’s date. You can also do something like: {!Today()+2} to manipulate the date plus or minus a certain number of days.

I hope this helps you take your Salesforce system to a new level of automation. If you get stuck just reach out to me and I’ll do my best to help you through the process. Once you master these tricks, you’ll find many ways to use them. Good luck and have fun!

Terry Miller
Terry Miller
Terry has spent over 20 years focused on business leadership and information technology. As an independent consultant, he enjoys working with a variety of customers to help them solve business problems using the Salesforce® platform. His ability to quickly identify bottlenecks and provide understandable solutions has gained him the trust of his customers. If you're looking for expert guidance on your next Salesforce® project, click here to contact Terry today.

7 Comments

  1. Salesforce.com Understanding the URL says:

    […] Home » Articles » Administrative » Understanding the salesforce.com URL Getting Salesforce Profiles Under ControlURL Hacking for Salesforce Automation […]

  2. Ramesh says:

    Hi Terry, Nice blog. As Salesforce discontinued supporting URL hacks, do you have any work around to pre-fill values. I am looking for an option to pre fill opportunity fields when opportunity is created from contact related list. Lead source from Contact should be pre-populated along with some custom fields, my earlier custom buttons with URL hacks stopped working.

    Also the action button does not help for pick list values and does not help if we need “Save and Add Product” button as the next step after opportunity creation.

    • Terry Miller says:

      You’re absolutely right, this will not work with the new Lightning interface. Actions are the simplest option but as you mentioned they also have some limitations. For the complexities of what you’re needing, I’d suggest you use a Flow.

      SF touts Flow as a great tool for admins who don’t code. That’s a bit misleading as even with flow you need to understand programming concepts. It mostly just hides/helps by eliminating the need to know the programming syntax. Anyway, that is likely your best option now. I miss the URL hacks! ?

  3. Joseph Kubon says:

    This is a great piece; my Admins are following the instructions to implement this during our current sprint. One catch – we still need the users to go through the “Record Type” selection page AND remember values to pre-populate on the new record layout. Any guidance on how to include that piece?

    • Terry Miller says:

      Honestly, my advice would be not to do this at all anymore. It’s not compatible with Lightning so you’ll end up having to redo it. What I’d recommend is looking into Actions. You can create new records and pre-populate values pretty easily with that method.

      • Joseph Kubon says:

        Thank you!

        Challenge remains the same with that feature because we have to select a Record Type or create 8 buttons for the various types. Don’t believe the Action has a dynamic feature for Record Type page. Agree? Or, am I missing something?

        • Terry Miller says:

          What I have done in those situations is to create a picklist field with the values that match the RecordType Labels. I don’t add this field to the page layout but instead create an Update Action that updates this field. It’s that only field on the Action. You can then use Process Builder or Apex to complete whatever next steps are needed.

Leave a Reply