Showing posts with label Formulas. Show all posts
Showing posts with label Formulas. Show all posts

Friday, November 20, 2015

Fun with Formulas: Clickable Links

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:
  1. Create a Formula Field (Type Text)
  2. Add the Merge Field Values to the formula
  3. Add the Hyperlink Syntaxt to your formula
  4. 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.

What does, "title=Call" mean? Well, it means that you are creating the "Call" type of task. The same one you would get when you click on the "Log a Call" link from a Task related list. This also sets the status of the activity to "Completed" by default, so your users just need to fill in details.

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.

Tuesday, January 28, 2014

Formula How To's: How do I extract an exact value from a comma separated list?

How do I extract an exact value from a comma separated list?

Recently, I was presented with the challenge of trying to extract an exact value from a comma separated list. In my scenario, I was trying to identify that one of the values in the list, was an exact match to a specific value on the current user's record. 

Why would I want to do this? Specifically, this allows me to use a "True" or "False" value in a list view, report or dashboard to display records. This presents the idea of a "dynamic" list, report or dashboard that is specific to the user viewing the list, report or dashboard without changing the data or the parameters thereof. 

Scenario:

As previously stated, I had a field that was a concatenated comma separated list. In my scenario this field was being set by a trigger, but regardless of how the data gets in the field the idea is the same. Next, I had a field on the user record that may have been a value in the comma separated list at anyone time on any given record. 

Formula:


AND(
If( 

/*Checking to see if the initials are here at all*/
Contains(Field_Im_Looking_at__c,$User.User_Field_value__c)
, True, False),
OR(

/*Checking for an exact match in the first set of values*/
IF(Find($User.User_Field_value__c+',', Field_Im_Looking_at__c)>0, TRUE, False),

/*Checking for an exact match somewhere in the middle. */
IF(Find(','+$User.User_Field_value__c+',', Field_Im_Looking_at__c)>0, TRUE, False),

/*Checking for an exact match at the end of the string */
IF(TRIM(RIGHT(Field_Im_Looking_at__c, LEN($User.User_Field_value__c))) = $User.Field_value__c, TRUE, False)
))

Break it down:

Ok, so breaking down this formula, I've changed the field names to "Field I'm Looking At" and "User Field Value" for simplicity sake. In the "AND" statement, I am looking to see if the value even exists within my set of values, and then the second condition contains my "OR" statement which searches for my exact value. You might not need the "AND" statement at all, and could probably do this with just the "OR" statement, but this worked for me and so I kept it like that.

Within the "OR" statement, I am checking for three conditions. They are:
  1. Is my value the first value in the list?
  2. Is my value a middle value in the list?
  3. Is my value the last value in the list?
The first two values are fairly easy to search for because I know that my value will look like: "VALUE," or ",VALUE," it's important to recognize the commas here. They are what ensure you are getting the exact value and not a partial value.

Note: If you have the scenario where a partial is possible with the end of the value (or in other words the first value in your list has a potential for being a partial), you might want to modify the first if Statement to be something like:

IF(Trim(Left(Field_Im_looking_at__c, LEN($User.User_Field_value__c))) = $User.User_Initials__c, TRUE, False)

In my scenario this wasn't possible and so I did not account for it.
What does that do? Well, simply it takes the value from the user record and trims everything but the number of characters for the value you are looking for. It then will compare the two values to see if they are a match. If they are, then you get a "True", if not you get a "False".

Application for use:

Now that I have this formula, I inserted it into a Formula Check box field. Now my users can leverage this field in list views simply looking for a "True" or "False" value to know if the records are applicable to them. This cuts down on a lot of complex reports and filtering for my end users. I hope it's helpful to you and as always this is one more thing that you can do in clicks and not code.