Clickable Links; How To:
One of my favorite tricks to use with formula's is creating a clickable link. Often I find that I want to have the link visible in a list view or in a report, in these scenarios a "Custom Link" just won't do. For this I look to creating a clickable link.
How is this helpful?
In many different ways this can be helpful or applicable. Imagine, you are a Sales rep, as a good sales rep does, you have a report of your top 100 clients. Each one of these is a contact, whom you want to stay in touch with regularly. The traditional way of handling this in Salesforce would be to click into each contact from the report, call them, and add the task to the contact saying that you have just called then and what you talked about. What if you could click on a custom link from the report called, "New Call" that would create a new task Record with various data points about the contact right from the report?
That would be a game changer, right?
How can I do it?
The execution is quite simple. I'll outline it in the following steps:
- Create a Formula Field (Type Text)
- Add the Merge Field Values to the formula
- Add the Hyperlink Syntaxt to your formula
- Expose to users/Add to a report.
Now that we know the overview, let's walk through this.
Walkthrough:
Step one, you should be familiar with, creating a new formula field of type text as shown below. We want to make sure that you put this field on the Contact object so that it can be exposed on Contact reports to fulfill the example scenario given above. Here's what it looks like so far:
Notice that I've named my field, "New Call" as to help my end users find it easily when adding it to reports. This way they know exactly what the field is for, simply by making my naming make sense. I didn't call it "New" which would be confusing to my end users as they don't know what they are creating that is "New".
Now on to the formula, what do I need to create a new task record in salesforce?
This part is simple, and you can do it by looking into your address bar when you go to create a new task.
Notice the "/00T/e" this is what will place my browser in the "Edit Mode" for the creation of a new Task. The /e is salesforce for "Edit" and the /00T is salesforce for "Task" all standard objects have something similar to this when you create new.
So I know I want my page to go here, so I'll add this to my formula. I'll also add the ? to my formula as this is necessary to begin passing in my field values to my new task I'm creating.
So far my formula is very basic, it looks like this:
But I don't want this formula because it would only display the text of "/00T/e?" which would mean nothing to my end users. I want this formula to be valuable, so the next thing I'm going to do is start adding my parameters that I want my URL to pass into my new task. I can do this with merge fields. If you remember the URL from above, you can look and see that a few fields are bing populated already for me. Can you tell which ones?
If you guessed, "Subject" and "Contact" you would be correct, and I would be impressed that you figured that out. It's not so simple with tasks as with other objects. There is a lot going on in this URL. Let's break it down so we understand it:
Well, we allready know that /00T/e? is creating a new task, putting us on the edit page and is ready for input value parameters to be passed.
Next, what is the "who_id" and what does that mean? Simplistically, that is the "Name" field, and the id you are passing is the id of the contact. This will auto-populate the contact in the Name field for you.
What is "followup=1" and what does it mean? The followup=1 is what allows you to create a follow up task at the same time as logging your call. You can remove this and just have your users log the call with no follow up.
Next is "tsk5=Call", this is the cryptic name for the "Subject" field. Very intuitive right? Right, well at any rate you are pre-populating the subject line for your end users. You could change this if you would like to "Call to Client", instead of "Call". Or "Phone Call" or anything you'd like really.
Finally, last but not least is the return URL. Where should your users be dumped after they have clicked save or cancel? Right now it's pointing to the contact record id. Meaning it will place them on the contact record. I could put this to the report id if I wanted, or the home page or anywhere else. For our example I will put it to the contact record as it makes the most sense to me. In order for this to work we have to include the %2F in quotes before the merge field Id.
Here is how my formula looks now that I've added the above parameters:
Notice the quotation marks and the & that I've added. The quotation marks are going to be important in making the breaks between exact text that you want to pass into the URL and the merge fields that you have. For example, the first set of quotation marks starting at "/00t...and ending at id=" allows me to then put in the merge field of Id. Since I'm creating this on the Contact object, it will be the contact Id. The & symbol is used to connect the various pieces of this formula. If you don't get these right the formula will not work.
As you can see I have "&Id&"&. This is essentially connecting my merge field to the front and back halves of the URL. The third & symbol is a continuation of my URL so that I can add another field that I want to populate. You MUST do this everywhere that you are going to populate fields with a merge field. That said, note that my last merge field at the end of the URL is simple "&Id. Effectively I've ended the URL so I don't need to attach it to anything else.
Now that I've added all of my merge fields, we simply want to make this a HYPERLINK formula so that the link will be clickable. I can do that by selecting the HYPERLINK formula on the right in the formula box. Then select insert function:
You should get a pre-formatted formula that looks something like this:
We are going to take and replace the part that says, "url" with the url that we have just built in the above steps. Then we are going to replace "friendly_name" with "Create New Call" (make sure to include the quotation marks. Finally we are going to remove the square brackets and replace the word target with "_parent". This will allow the link to open in a new window. If you want it to open in the same window you can use "_self" instead.
Here is what that looks like:
Now you've created the field. You want to make it visible to all of the users that you want to be able to use it, but you probably don't want to put this on a page layout. This is better used in list views or in reports so that the sales users can have a list of contacts they are contacting and work their way down the list.