+ Start a Discussion
Jun TeppangJun Teppang 

Spring 20 - Navigate to a Record’s Create Page with Default Field Values - Return URL not working

As of Spring 20 release, we can again prepopulate field values using a URL - aka URL hacking (see release note here (https://releasenotes.docs.salesforce.com/en-us/spring20/release-notes/rn_general_lex_navigate_to_record_dfv.htm)).

I, for one, am so happy for this feature. However, there is one minor problem. When the URL is invoked, the new record modal pops up, and if the user chooses to Cancel, a blank page is displayed instead of returning to the page where the URL was called.

Below is the URL that I'm using. It is invoked with a custom list button located in a related list of an Opportunity.


I've tried including a retunURL parameter - in different places in the URL. But no luck.
Jun TeppangJun Teppang
If anyone is intereseted, I think I've figured out a solution to specify a return URL for this. And as an added bonus (thanks to 
Iqbal Hossain 1 (https://developer.salesforce.com/forums?feedtype=RECENT#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Developer_Forums&criteria=ALLQUESTIONS&id=9062I000000XrIqQAK)) you can also specify the record type id:

Here is the updated sample URL (reminder that this is invoked by a custom link button located in a related list of an Opportunity record):

/lightning/o/Case/new?recordTypeId=<insert your record type id here>&

And for those using lighting/navigation in LWC, here is a sample function code:
  this.defaultValues = `AccountId=${this.accountId},Opportunity__c=${recordId},ContactId=${this.contactId}`;  
  . . .

  navigateToNewRecord() {

        this[NavigationMixin.Navigate]( {
            type: 'standard__objectPage',
            attributes: {
                objectApiName: 'Case',
                actionName: 'new',
            state: {
                recordTypeId: <insert your record type id here>,
                defaultFieldValues: this.defaultValues
Note that you don't need the "backgroundContext" parameter.

Hope this helps someone out there!

Craig Maxwell 37Craig Maxwell 37

A slight aside however, for record types you can also use this method to envoke the record type selector:

I found this very handy, just wanted to share and hoping it might help others stumbling accross this thread.
Vijay VadgamaVijay Vadgama
Hi Craig / Jun,

I was wondering if someone can help me?

I'm actually having an issue when trying to save the record (pressing "Cancel" on the record is fine). 

Let me give you some background:

As we're transitioning to Lightning, the business is requiring Lead information to be populated to activities (which can't be done using Actions). I've created a URL hack for "New Task" which displays near the buttons on the Lead lightning page. Pressing the "New Task" button (and cancelling) is working fine, but when I try to "save" the Task record, it re-directs me to the Task page, despite having &retURL at the end of my hyperlink. 

I've tried every possible solution I can think of, but this issue still persists. Can somebody please help me if they know how to return to the record the button was pressed on? (in my case, Lead)

My URL example:

Jordan Wight 7Jordan Wight 7
@Jun - Is this working only for a custom link? I tried this using a custom list button, and it's not working for me.
Lee Anne GLee Anne G
We too, had a related list and a custom button to add a new Opportunity Contact Role. Once we switched to lightning the default value (the opportunity this new Contact was related to) and the Cancel button were no longer working as suspected. Here's the syntax I used to fix it to work in lighting. ** Please note that our Opportunity object and it's related Opportunity Contact Roles object are both custom objects.


Now, when we're on the related Opportunity Contact Roles list and we click the Add Additional Contact button, the Parent Opportunity is there by default and if we hit cancel, it's no longer blank. :-)