The Art of URL Hacking in Salesforce : Part I — New Record Creation
URL Hacks have been in usage in Salesforce by Developers, since a long period of time, as URL Hacks via Buttons / Links often help a Developer to deliver a custom requirement from business without much customization.
Some of the major use cases for Salesforce URL hacking are as follows:
- Defaulting record types for newly created records.
- Pre-populating values on child records created from parent.
- Controlling the Navigation on click of the Cancel button in New Record creation Dialog box.
- In Orgs with heavy customization, where New Button is overridden with a VF/Aura/LWC Page, Overriding this override and viewing the Standard Salesforce New Record creation Dialog box.
With every Awesome thing, there are always some limitations associated to it & so is the case for URL Hacks.
- These URL hacks often do not work on Mobile [Unless you create a whole Dynamic URL hacking Custom Component, that ultimately handles both Desktop & Mobile — Something, that I have been trying to build in my personal Org]
- These also do not work in Lightning Out, Lightning communities as of Spring’20 Release Doc, but I’m yet to try and check it, if there was some Salesforce Release that fixed this.
- Potential Security concerns.
- Salesforce Future Release may someday impact this feature, if Salesforce changes the way they pass data in background & perform the URL redirections.
I’ll really recommend you to consult with your Salesforce Technical Architects & Security Experts before using these URL hacks, as although these work perfectly satisfying all the Business requirements, but they are indeed hardcoded URL hack at the end of the day.
Before we begin with the URL Hacking topic, I would really recommend you to read a bit about URL Encoding & URL Decoding & if you are in for a full deep dive or are in the mood of going all nerdy, read about Base 64 Decoding as well, as all these concepts are used in Salesforce URL Hacking.
Let’s see how one can create a New object record by passing specific parameters into the URL.
Note: URL should not have any new lines in between them.
“New” Object Creation in Lightning Experience via URL hack.
E.g. URL Hack to Create a New Task Record from Account Record Page, which allows user to select the Record type (if multiple exist for the object), show Account’s Record page in background and if user Clicks on Cancel button, land back to Account’s Record page and populate the following fields:
Related To ID = Account Record , ActivityDate= Account’s SLA_Date__c, Subject = “From Account”, Reminder Set = Checked, Task_SLA_DateTime__c = Account’s Activity_Date__c Date & Time and Description = My New Task.
/lightning/o/Task/new?nooverride=1&useRecordTypeCheck=1&defaultFieldValues=
WhatId={!Account.Id},WhoId=null,ActivityDate={!TEXT(Account.SLA_Date__c)},IsReminderSet=true,Task_SLA_DateTime__c={!TEXT( DATEVALUE(Account.Activity_Date__c) )}T{!TEXT( TIMEVALUE(Account.Activity_Date__c) )}Z,Subject={!URLENCODE('From Account')},Description=My+New+Task&backgroundContext={!URLENCODE('lightning/r/Account/{!Account.Id}/view')}
Base URL: The base of the URL hack is “/lightning/o/Task/new?” which means that we are trying to create a New Task Object record and the ? part follows the list of parameters to be passed along with the URL.
Parameters used in the URL :
- nooverride : nooverride=1 attribute is used if in case you have overridden the New button on the object with a Custom VF/Aura/LWC page.
- useRecordTypeCheck: useRecordTypeCheck=1 attribute is used to display the Standard RecordType Selection dialog box, if the Object has more than 1 Record types.
Note: This will override the recordTypeId attribute passed with the URL hack. - recordTypeId: If you have an Object with multiple Record types and want to hardcode a specific recordType Id for New Records to be created by URL hack, then we can pass it via this attribute. This attribute is case sensitive. E.g. /lightning/o/Task/new?recordTypeId=012B0000000YOIg3&defaultFieldValues=…..
- defaultFieldValues : This attribute is used to pre-populated data in certain set of fields defined in the URL (hardcoded data value / data coming from Merge fields). There are couple of Notes for passing Data in URL via defaultFieldValues attribute :
a] DateTime Field: Salesforce supports the “<Date>T<Time>Z — e.g. 2022–12–01T02:15:00.000Z” format. So we’ll have to separate DateTime into Date and Time and then use Text to convert it as String & hardcode T and Z format.
b] Date Field: For the Date field, we can use the TEXT method only or DATEVALUE method with TEXT method
c] Text and Other Fields: For Text and other fields we can pass them using URLENCODE method. (Tip: If you only want to add spaces, you can also use + or %20, which are the same as above URLENCODE method)
d] Picklists: For Single Value Picklists we can pass them using URLENCODE and TEXT method together. E.g. {!URLENCODE(TEXT( ))}
e] Multivalue Picklists: For Multi Value Picklists we can pass them using URLENCODE and TEXT method together, separating the multiple values using “;” operator
f] Checkbox Field: For Checkbox fields we can pass true or false.
g] Lookup Fields: For Lookup Fields, pass the Id value for the Lookup field, salesforce will automatically handle the rest. - backgroundContext: This is used to set the background when the New Object creation dialog box opens and also when the user clicks on cancel, they will land back on the page URL passed as value to this attribute. Use URLENCODE method to convert “/” to %2F.
a] Open Account Record Page :
&backgroundContext=/lightning/r/Account/{!Account.Id}/view
b] Open Account Recently View List View:
&backgroundContext=/lightning/o/Account/list?filterName=Recent
c] Open Home Page:
&backgroundContext=/lightning/page/home
d] Open Chatter Page:
&backgroundContext=/lightning/page/chatter
e] Open a Tab :
&backgroundContext=/lightning/n/<Custom Tab’s (Entity : 01r) DeveloperName>
f] Similarly, you can pass some other valid Salesforce URLs as well here, the possibilities are endless…. - navigationLocation: This attribute is used specifically to return to a specific page after clicking on save button, For example you have created a List Button visible on a Related List to create a new Child object of Account and post clicking on Save button, you wish to navigate back to Account’s Related List, then use &navigationLocation=RELATED_LIST. Currently this attribute supports only ‘RELATED_LIST’ & ‘LIST_VIEW’ as values.
Some websites that can help you to perform URL Encoding & Base 64 Decoding.
I hope you enjoyed this article 📖 & found it insightful! 🔍!
Do hit the clap button👏 if you liked the article & leave a comment✍ if you have any queries/suggestions.
Enjoying the content? Don’t miss out on my future posts! Hit ‘Follow’ button to be the first to know about my new publications 🔔. Can’t wait to share more! 🚀🎉
Thanks for reading!
Here’s the Link to Part II of my Salesforce URL Hacks Article.