In Blog, Releases

URL Hacks are back and in Lightning with Spring ’20

Before the coming of Salesforce Lightning Experience, I was a big fan of URL Hacks. These not officially support features gave us to the capability to change Salesforce funtionalty by simply changing the information in the URL. Common use cases was to pre-fill the “new record” screen or fill in or change a field in the “edit record” screen. We could do some crazy automation-like things. I wrote about URL Hacks a lot.

Then Lightning Experience cam and with it, the official outlawing of URL Hacks.  Instead, we were given actions and ability to pre-fill forms that were not the full “new” or “edit” screens but some poor approximation. We also lost all the other cool things we used to be able to do by simply hacking the URL. I grew despondant. I was a very vocal advocate for doing something. I was so sure that URL Hack functionality needed to be there, that I figured out how to do it with Flow. Combining Flow and Lightning Component Local actions we could do a lot that was URL Hack like. Doug Ayers took my concept one step further and gave you an actual URL hack -albiet one that required a lot of code.

I was very surprised when I opened up my copy of the Salesforce Spring Release Notes and discovered that URL Hacks are back in Lightning! Kind of, some what… and I also discovered that despite years of screaming I want URL Hacks, I’m pretty annoyed at this.

So URL Hacks are back in town. Let’s look at what you can do with them and why you may not want to use them. On the bright side, I get to re-use a feature image from a previous post.

How They Work

URL Hacks in Lightning are a bit better than in Classic in one way – the URL is easier.

In classic, we had to find out what the Field’s Name/ID was in the HTML and reference that in the URL. The big problem was those references changed from Sandbox to Production and potentially whenever your instance changed. It was very annoying since you couldn’t pre-fix things. You had to wait until they were broken and THEN fix the issue.

The example the Release Notes provide looks like this:

    CustomCheckbox__c={!IF(Account.SomeCheckbox__c, true, false)}

Let’s break that down.

When we create a new Account the URL is currently: /lightning/o/Account/new?

That’s identical to the URL hack and hasn’t changed. The new bit comes after the question mark and that’s “defaultFieldValues=” In our URL Hack Parlance this is a URL Parameter. After the questionmark the browser knows anything afterwards is a parameter. All parameters are in a key=value format. So for this example, our key is defaultFieldValues and our values are a combination of Keys and values for the field and their values.

Name={!URLENCODE(Account.Name)} this part is important. The important bit is URLENCODE. This is a function that will take any non-url friendly character and convert it to a friendly version. For example, if the account name was “Better Partners” URLENCODE will turn it to “Better%20Partners” Spaces are not acceptable in the URL Format. Anything that is not just a list of numbers, a single word, or contains any funky characters will need the URLENCODE function

Then we have a comma to separate the next field and value pair. This is significant since in typical URL Hack we would separate fields with a & to denote a new parameter. In this circumstance all the Field/Value pairs are really just 1 value to the defaultFieldValue key. So it’s not as simple as copy/pasting existing URL hacks from classic. You will need to do some conversion.

Why I No Longer Like URL Hacks

First, I totally understand why people like URL Hacks. They’re fast. They’re “easy.” They gave us access to the full page layout. We could also do some funky other stuff in Classic.

In Lightning, we can only create new records. While this is nice, I personally prefer to use a Lightning Component or a Flow with a Lightning Component action instead to get the URL Hack functionality in Lightning.

URL Hack Functionality In Lightning?!

Why? Well for a few reasons. First, I think it gives us more ability in the long run. Yes, you need to have a custom lightning component, but in the circumstance for creating new records it’s not that difficult to do and involves no Apex code. Second, it uses 100% lightning supported features which means it works in Mobile. Third, because we’re using Flow and Lightning Components, we may be able to do other things besides creating new records.

More Ability

This currently works ONLY for new records. I tried to create a URL Hack so we could update an existing record. The URL Format is a bit different: /lightning/r/Contact/0030M000028DAvKQAW/edit?

Note that instead of an “o” it’s an “r” before the object. We also have the record Id and the word “edit” instead of “new.” I was hoping by simply adding defaultFieldValues= after the the question mark I could add more information. For example /lightning/r/Contact/0030M000028DAvKQAW/edit?defaultFieldValues=description=Test%20Hello This doesn’t work.

So we can only create new records.


Lightning is very handy because it’s now the system that drives our mobile platform – especially in the Spring 20 release.  I created a URL hack that simply defaults the name of the account and the description.  I took my sample URL Hack and tried in mobile.

My result:


URL Hack Spring 20 in Mobile

URL Hack Spring 20 in Mobile

Not exactly what I call friendly. Since the Lightning buttons/actions and the mobile buttons use the same set up on the page layout – you’re stuck. This is especially true if you have users that use both Desktop and Mobile and cannot create a mobile only page layout.

The Flow/Lightning Component Action solution does work in mobile.

More Functionality

This is a bit redundant with the first option. The fact is because in my example we use flow and Lightning Components, we can create a whole bunch of cool automation. We could create a “hack” that sends email, creates records, update records, does a bunch of stuff and navigates us to a new page. Why we would want to limit ourselves to a URL only is mystifying to me now. I understand it’s easier for lots of folks to wrap their head around, but the automation platform is going to Flow. It’s something you’re going to want to learn and should learn.

For me, the new URL Hack functionality in Spring 20 is a short cut. If your only need is to create a new record, default field values, and a action isn’t good enough – go right ahead and use it. But if the main reason you’re doing it is because you don’t think you can handle using a Flow with some Lightning Component actions – then stop. Take the time to learn how to do it. The URL Hack may be an acceptable short-term, “I need this out right now” solution, but you’ll be closing your off to the amazing capabilities you could do with just a little education and imagination. Plus, who wants something that only works in desktop and fails in the mobile world these days?

Don’t miss a post! Sign up to receive email notications.


Subscribe to our mailing list

* indicates required
I want to receive email notifications about:

I run this site, the podcast, and my training videos for the community. I do incur some costs. I greatly appreciate if you can help me out by checking out my affiliates and – if you shop amazon – start your search on my site.

Recommended Posts
Showing 30 comments
  • Chris Pearson

    I have been waiting for an explanation on the “why” for this feature – especially given the age of Lightning and how we should have been avoiding URL hacks for years. Thank you, Brian, for a great article!

    • Brian Kwong

      I think the “why” has been a lot of people wanting it and complaining.

      I do like their method of making it more “Standard.” No more going to find HTML IDs for example.

      But I would preferred if they released some standard lightning components that we could re-use. Like Navigate to an sRecord, create/edit new record where we’re passing in the values. The defaultFieldValues is actually one of the attributes in the Lightning Component to create new records, so that may be exactly what they’re doing, using a lightning component but providing access to an attribute via a URL Parameter. But I prefer to create a custom link, custom button, custom action, or hyperlink formula that is accessing that component directly and letting me pass the attributes in. I think it’ll be more flexible in the long run. But I’m not a product manager.

  • Dhana

    Hi, Trying to understand if the below URL hacking is doable through the Lightning. We have a custom button in Classic which calls the list view of Custom object like (where fcf is the view on the Custom Object type a3Y)


    • Brian Kwong


      From what I can tell, the only URL hacks for Lightning that are supported are filling in report parameters and navigating to a NEW record page.

      What’s your business case for the custom button? Since we can put list views on the lightning page, I would add a new tab (assuming this is a record page) and have that tab with the list view component.

  • João Silva

    Hey great article! I currently creat an object in edit mode as you described above, but after i save it it doesnt return to the object’s page in view mode. any tip on how to do this?

    • Brian Kwong

      So you’re saying you’re editing a record, click a button create a new record, and you expect to see the view of the starting record?

  • Loren

    I am doing a lightning hack to create a new opportunity from the account. However, I can’t get the account name lookup to be filled in on the new opportunity record creation! What am I doing wrong?

    AccountId = {!URLENCODE(Account.Id)}

    • Brian Kwong

      Loren, a few thoughts, you shouldn’t need to URLEncode a Salesforce id since it’ll only ever contain numbers and letters. THat’s really for things that have spaces, commas, apostrophes and so forth.

      Also, I’m a big fan of using a fully baked URL for testing outside of a button or link. You can simply paste your URL into the browser, see how it works, and make changes until you get something to work. Unfortunately, salesforce doesn’t always show you the resulted URL when it’s called from a button. It does show it when you call it from a link but it quickly changes to some nonsense.

      For example. Past — obviously use your Instance name and not thewizardnews and actual account id.

      And see what happens. I got it to work doing it this way. The only thing to know is you can’t have any spaces in the URL so AccountId = IDvalue is wrong. AccountID=IdValue is correct.

      Again, I only recommend using URL hacks like this if you NEED to have the full page layout when creating a child, or if you’re creating a record that is not a child of the starting record. A custom create action is simply better and easier in those use cases.

  • John

    Been struggling to find a way to use these with other formula elements all afternoon and have come to the conclusion that it isnt happening I think. For example, if you wanted to do {!IF(abc=abc, , other url,)} you need to be able to put something surrounding the lightning hack to use it in the IF (as it starts with a / and has commas in it). As soon as you do that, it blows up when you press the button by trying to encode it (or something) and either takes you to an error page in lightning in a new tab for some reason, or the home page. It looks to me like the parameters included after defaultFieldValues are not included in the URL itself so having them within, for example quote marks, is putting them in the URL which seems to not be how this works.

    Anyone had any luck with something like this?

    • Brian Kwong

      I’ve had luck. The way lightning works makes it difficult to test and debug these because the URl doesn’t actually show up at the final result screen.

      If I use a link instead of a button I have seen the URL show up for a short period of time before the browser moves to the next URL which is the final result. I’ve had some success grabbing the URL and seeing how the link/button is being resolved to figure out problems.

      The other thing you can do (in a sandbox obviously) is to take your formula and create a formula field. You won’t be able to use it as an actual link, but you can see how your functions and formula resolve for that record.

      Keep in mind you only need to URLEncode the bits that could have things problematic (spaces, apostrophes, etc) and you don’t have you URLEncode the whole URL string.

  • Glenn Seidenfeld

    Hello Brian,
    Is it possible to set a default value for a field as a specific account record that acts as a placeholder? lightning/o/Account_Referral__c/new?defaultFieldValues=Lead__c={!Lead.Id},client__c=specific record here

    • Brian Kwong

      You could hard-code a record ID (assuming client__c is a lookup field). However, I don’t recommend it since if anything happened to that record, you’ll break your button.

      unless your value for client__c is coming from the record so you can grab it via a field merge

  • Andy

    The only reason I want to implement this at all is because the standard “New” button on a related list doesn’t fill in values in Lightning as they did in Classic.
    Does this work with list buttons in a related list? I’m not having any luck.
    From parent Opportunity, trying to have a “Make me a new Quote” button on the Quotes related list. And have it fill in the Opportunity lookup, Account lookup, and Sales rep lookup on the new Quote record.
    (Alternative is to hide that new button and instead retrain users to use Actions. But sometimes the new button comes back….)

    • Brian Kwong

      I haven’t had any luck with it on related lists.

      However, I’ve been able to do Flows (with local action) to replicate the functionality. No coding involved. This walks through the process

      I’ve also used straight Lightning Component but I have found some odd foibles to it when users click, exit out, and then attempt to click it again. That can found as a post by Doug Ayers – linked at the bottom of the post I listed above

  • Silvia

    I need to replace a URL hack we build to open a new email screen with a pre-determined template (based on a formula field). Any suggestions? This is our classic button:
    /_ui/core/email/author/EmailAuthor?p2_lkid={!Enrolment_Form__c.Student_NameId__c }&p3_lkid={!Enrolment_Form__c.Id}&template_id={!Enrolment_Form__c.AUS_DOM_Offer_Template_ID__c}&p24={!Enrolment_Form__c.Student_Email__c}&new_template=true&{!Enrolment_Form__c.Id}

    • Brian Kwong

      Lightning URL hacks only are supporting creating new records. So it doesn’t support the email setup at all. The email system is completely different in Lightning so you wouldn’t be able to update it. I don’t think there’s a LEX support method of doing emails. The closest I could get you is an action that calls a flow & send an email alert. That would mean that the user couldn’t modify anything in the email and you would have to have a field to store the recipient of the email on the record you’re clicking the button from.

  • Karen Spence

    Do you have a URL hack to clone a Quote? We have a URL hack for classic to clone a quote, which Salesforce doesn’t support. I’m trying to convert to lightning but not there yet. Would love some help. Thanks!

    • Brian Kwong

      I haven’t tried the URL setup for lex with Quotes. If it works, I would imagine it’ll be the same setup around /lightning/o/Quote/new?defaultFieldValues= … followed by the mappings of source quote to new quote to “clone” your quote.

  • yona adler

    Hi Brian,
    I was wondering if there’s a url hack for loading a record based not on a Salesforce id but on a custom unique id. not sure if this is possible but I’m hoping htere’s a way.

    • Brian Kwong

      Not to my knowledge. URL Hacks were never officially supported and now are only supported in this very narrow example.

      What’s your use case? Depending on what/where you want it to occur you might be able to get away with a Flow that takes your Custom Unique ID, matches it to a salesforce ID and then navigates the user to the proper record.

  • Gaylene Dickens

    Hi Brian,
    I’m trying to replicate a button in lighting that will create a case from an opportunity. I’m getting a similar error as you show in mobile when it runs. Sometimes I can see the case layout appear for a brief second but then get the dreaded “Looks like there’s problem” message. My URL hack is (api field names are used for the opp name and account name):

    I’m pulling my hair out.. thanks for any help!

    • Brian Kwong

      Chances are the issue is with what you’re assigning in the defaultFieldValues

      I’m guessing Opportunity__c is a lookup field. If that’s correct, that you don’t want to merge Opportunity.Name you want to use Opportunity.Id — also assuming your URL button is on an Opportunity.

      A good way to handle debugging this is taking it one step at a time. So start with /lightning/o/Case/new … did it work? great, then add recordTypeId… did it work? add 1 field for defaultFieldValues… it’ll help figure out where the problem is.

      • Gaylene Dickens

        Thanks for the guidance! One thing I have noticed is that the URL Hack uses the default record type of the user. Even if the record type is called out the logged in user will get the create/edit screen of their default type. At least that has been my experience so far.

  • BM

    These button don’t support in classic. Is it really works only in Lightning

    • Brian Kwong

      You’re right, this setup of URL Hacks do only work in Lightning. It’s really not even a hack because it’s supported by Salesforce. They’re completely different from the Classic URL hacks other than we can pass certain things into a page through a URL. The defaultFieldValues is setting something in a lightning component which aren’t available in classic and therefore it won’t work and are not intended to work.

  • Adam

    Curious if there is a way to use a URL Hack for the Global search that also references an existing field. Idea is: to be able to click a button or hyperlink on a Lead record and search SF with the Email Domain of a Lead (Email Domain is already a formula field). Thanks for any help.

    • Brian Kwong

      Not that I can see in Lightning. Even if you could it wouldn’t be supported. the URL hack here is technically not a hack. SFDC appears to be basically exposing their own Lightning component to accept URL params. That’s the only part of this that is supported.

      If you look at the URL when you do global search it looks like*long_gobbly_glob_of_characters

      there’s no actual values being passed in the URL unless it’s encrypted and thus the long character string. Interesting use case though

  • brian borbely

    Thanks for the read, Brian!

    Do you know if it’s possible to create a Contact Role record while creating an opportunity? I know it was possible in classic but I haven’t been able to recreate this in lightning.

    Something similar to this:

    Second question, are. we able to dynamically set the “My Domain” and Org instance in a URL button? It’s a pain needing to update buttons in refreshed sandboxes.


  • Brian Borbely

    Hey Brian, is there a way to create an Opportunity Contact Role record when creating a new Opportunity from a Contact URL button in lightning? I saw your post using the conid parameter for Classic. So I am hopeful there is a similar solution in Lightning.


    • Brian Kwong

      Hey Brian.

      I’m not aware of being able to do this with the URL Hacks that are supported in Lightning. Some options though:

      1. Use a Flow instead of a URL hack. There’s some downsides to this, but the plus side is you can create all the related records you want (more or less). This is pretty viable if you don’t need the Full page layout when creating a new opportunity
      2. User after-create automation (process builder or flow) and create a text field on the Opportunity for the “originating contact.” You would then use your URL hack to set the value of that field to be the ID of the contact role and then your automation gets fired after the Opportunity is created and there’s a value in that field. The automation uses the Contact ID to create the contact role.
      3. Create a custom lightning component instead of using the URL hack

      And that’s all I can think of off the top of my head. My personal opinion is to go with route 2. The downside is the contact role will not be immediately visible when the user views the new record. This is due to the automation happening AFTER the record is created – which makes sense. You can’t create a related record until the parent exists first. This will only come into play if they’re immediately redirected to the Opportunity when it’s created. If they have to click from the contact to the Opportunity that should be plenty of time to have the role get created

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.