Salesforce URL Hacking for Lightning

Are you still missing the Salesforce Classic URL Hacking in Lightning Experience? You may remember that lightning Experience initially don’t support URL Hacking in Salesforce and that was replaced with Custom Actions. Don’t worry Spring 20 Release highlight the URL Hacks are Back. Let see how to Navigate to a Record’s Create Page with Default Field Values.

What is a Salesforce URL Hack?

URL Hack is create a custom button that creates a new record with some presets default values using static or dynamic fields based on the record you’re currently on. Instead of asking users to click the standard “Create New” button and fill all information from scratch on screen, you could use a custom button to create a new record and pass some default value on page to save your users some keyboard time!

URL Hacks are Back

In Spring ’20 release notes Salesforce provide the new tricks for us to Navigate to a Record’s Create Page with Default Field Values, Now you don’t need to check and decode the URLs to find the secret sauce. The old URL Hacks also used the field Ids rather than API names. With this trick we can use Field API names.

URL Hacking Example

Create custom buttons and links that pass default field values to a new record. To construct a custom button or link that launches a new record with prepopulated field values, use this sample formula.

/lightning/o/Account/new?defaultFieldValues=
    Name={!URLENCODE(Account.Name)},
    OwnerId={!Account.OwnerId},
    AccountNumber={!Account.AccountNumber},
    NumberOfEmployees=35000,
    CustomCheckbox__c={!IF(Account.SomeCheckbox__c, true, false)}

Let see how we can create opportunity record with some per-populated values while create from Account object.

1: Create the Custom Button and Add URL

2: Add on-page layout

3: Testing

URL Hacking Restrictions

Yes we have some restrictions that apply to the new URL Hacks

  1. Not available in Community
  2. Not available for Salesforce Mobile Aoo.
  3. They also wont work with Lightning Out
  4. Passing the RecordTypeId to defaultFieldValues isn’t yet supported
  5. The URLENCODE function works only when creating custom buttons and links. You can’t use it for custom fields.

Lightning URL Hack with Record Types

Regarding prepopulating the Record Type, it can be done but the parameter needs to be passed as an independent parent parameter, outside of default field values.

Example Lightning URL Hack with Record Types

/lightning/o/Account/new?recordTypeId=yourRecordTypeId&defaultFieldValues=
Name={!URLENCODE(Account.Name)},
OwnerId={!Account.OwnerId},
AccountNumber={!Account.AccountNumber},
NumberOfEmployees=35000,
CustomCheckbox__c={!IF(Account.SomeCheckbox__c, true, false)}

Summary

Simply construct a custom button or a link that launches a new record and use the sample formula to prep-populate your field values using Salesforce URL Hacking for Lightning. Stay tuned and Subscribe the blog for more Tips and trick.

Amit Chaudhary
Amit Chaudhary

Amit Chaudhary is Salesforce Application & System Architect and working on Salesforce Platform since 2010. He is Salesforce MVP since 2017 and have 17 Salesforce Certificates.

He is a active blogger and founder of Apex Hours.

Articles: 461

9 Comments

  1. Very helpful article!
    Regarding prepopulating the Record Type, it can be done but the parameter needs to be passed as an independent parent parameter, outside of default field values.
    Example:

    /lightning/o/Account/new?recordTypeId=yourRecordTypeId&defaultFieldValues=
    Name={!URLENCODE(Account.Name)},
    OwnerId={!Account.OwnerId},
    AccountNumber={!Account.AccountNumber},
    NumberOfEmployees=35000,
    CustomCheckbox__c={!IF(Account.SomeCheckbox__c, true, false)}

  2. Hi,
    Its really great pleasure to learn from this platform. As I just wonder to know ,Like i f we do have “Clone ” option on record detail page.. why do we need salesforce URL Hack ? can you please let me know as I am learner here , so i may sound novice.

    Thank you

  3. After creating a record, do you want the user to remain on that record rather than being returned to the previous screen? The undocumented hack for this is to set/add a parameter for &navigationLocationId= and leave it blank. The lack of a originating location confuses Salesforce and means it navigates to the newly saved location. ?

    n.b. In my testing &navigationLocationId= was the last item (just in case placement makes any difference).

Leave a Reply

Your email address will not be published. Required fields are marked *