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.
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:
https://na11.salesforce.com/003/e?retURL=%2F001G000001p781C&accid=001G000001p781C&RecordType=012G00000014LM5&ent=Contact
/003/e?retURL=%2F001G000001p781C&accid=001G000001p781C&RecordType=012G00000014LM5&ent=Contact
/003/e?retURL={!Account.Id}&accid={!Account.Id}&RecordType=012G00000014LMA&ent=Contact
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.
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:
Option 2: (works only on custom fields only)
Option 3: (this is my least favorite method as you’re literally reading the page source code)
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.
&[the field id]=[the field value you want auto filled]
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:
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!
7 Comments
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.
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! ?
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?
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.
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?
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.