URL Hack in Lightning to Pre-populate fields

Prashant Pandey
2 min readApr 28, 2020

--

The Spring’20 release has simplified the Lightning URL hack very similar to the classic version.
By default, Salesforce only populates the fields on the related record but if you need to populates other fields when creating the new record in Lightning use Lightning URL Hack.
The Lightning URL nothing but taking the standard URL and enhancing it with additional parameters to populate the required fields.
Here are the steps to construct the URL hack and use it by creating a new custom button.

1. Get the standard Lightning URL that salesforce construct when creating new Record
2. Identify the fields and their API Name that you want to pre-populates.
3. Assign the Target fields(The field you want to prepopulate) to Value Pair for the additional fields to be populated.
4. Create a custom URL button.
5. Add the button to the desire page layout.

Let's see a few use case of how to pre-populate the lookup field(WhatId) from Account to create Task (Use Case 1):

/lightning/o/Task/new?&defaultFieldValues=
WhatId={!Account.Id}

Let's break these URL into different components and understand how it works.

Use Case 2: Pre Populate Task Subject and the Status field which is nothing but prepopulating the text and picklist field with URL hack

/lightning/o/Task/new?&defaultFieldValues=
WhatId={!Account.Id},
Subject=Call,
Status=Completed,
Priority=High

Use Case 3: Pre-populate the Task’s Activity Date to the current date.

/lightning/o/Task/new?&defaultFieldValues=
WhatId={!Account.Id},
ActivityDate={!TEXT(TODAY())}

Here I am wrapping the date field in the text so that browser can read it.

User Case 4: Pre-Populate the specific recordType of Task

/lightning/o/Task/new?&recordTypeId=your recordTypeId &defaultFieldValues=
WhatId={!Account.Id}

Use Case 5: Suppose you have given the assignment to create a button on the account that will create a task record with pre-populated task subject depend on the account field called Type.

/lightning/o/Task/new?&defaultFieldValues=
WhatId={!Account.Id},
Subject={!IF(TEXT(Account.Type)=’Prospecting’,’Call’,’Email’)}
Step 4: Custom URL button

In the above example we are checking if the given account is Prospecting then populate the call else pre-populate the Email In the subject field.

The final steps are to add the above button to the right page layout on the account object.

--

--