Supporting Report Filter URL Hacks in Lightning and Classic

Ahh, the fabled URL hack. For years, Salesforce admins have used formulas to create dynamic URLs behind custom links. The classic use case is linking from a record to a report, and having that report be filtered to information relevant to that particular record. In the Classic UI, this was (and still is) pretty easy to achieve by creating a formula field like this:

You add one URL parameter to the link that represents the report filter, and pass in the Record ID tag.

When the Lightning UI came out, many admins were disappointed (horrified?) to learn that their beloved URL hacks wouldn’t work in Lightning. Salesforce product managers heard the feedback, and in the Spring ‘17 release, we got the ability to filter reports via URL parameters in Lightning! Here’s the basic syntax, as it appears in the release notes, used in a HYPERLINK as we did above:

But wait! That looks different! Indeed it is. The Lightning URL hack is different from the Classic URL. OK, so we can update our formula fields…but what happens if your org has some users in Classic and some in Lightning? Two different formula fields? Ugh. What’s an Awesome Admin to do?

Community to the rescue! Salesforce MVPs Thomas Taylor and Jeremiah Dohn both came up with a very clever way to create One Link to Rule Them All! Let’s take a look… (Did you know you could put comments in a formula field? Bonus tip!)

We’re using 2 key functions here: HYPERLINK generates the link itself, and IF lets us check the user’s displayed theme. Essentially we say if they’re in Lightning (AKA “Theme4d” behind the scenes), use the Lightning syntax, otherwise use the Classic syntax. Pretty simple, once we take advantage of that $User.UIThemeDisplayed parameter!

Unfortunately, this cleverness isn’t tolerated by custom buttons, but it is tolerated fine by links in formula fields. I suggest converting any filtered-report buttons into links for the duration of your transition to Lightning.

If you are working on the Lightning transition at your organization, check out the Lightning Experience Rollout module on Trailhead. Once you’re ready to level up your skills, dive into the Lightning Experience Specialist Superbadge.