You need to sign in to do that
Don't have an account?
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.
/lightning/o/Case/new?defaultFieldValues=
AccountId={!Opportunity.AccountId},
Opportunity__c={!Opportunity.Id}
I've tried including a retunURL parameter - in different places in the URL. But no luck.
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.
/lightning/o/Case/new?defaultFieldValues=
AccountId={!Opportunity.AccountId},
Opportunity__c={!Opportunity.Id}
I've tried including a retunURL parameter - in different places in the URL. But no luck.
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>&
defaultFieldValues=
AccountId={!Opportunity.AccountId},
Opportunity__c={!Opportunity.Id},
ContactId={!Opportunity.Contact__c}&
backgroundContext=%2Flightning%2Fr%2FOpportunity%2F{!Opportunity.Id}%2Fview
And for those using lighting/navigation in LWC, here is a sample function code: Note that you don't need the "backgroundContext" parameter.
Hope this helps someone out there!
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.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:
/lightning/o/Task/new?defaultFieldValues=
{!IF(ISBLANK(Lead.AccountId__c),'','WhatId='&Lead.AccountId__c)},
{!IF(ISBLANK(Lead.Primary_ContactId__c),'WhoId='&Lead.Id,'WhoId='&Lead.Primary_ContactId__c)},
Lead_Lookup__c={!Lead.Id}
&retURL=%2F{!Lead.Id},
backgroundContext=%2Flightning%2Fr%2FLead%2F{!Lead.Id}%2Fview
Regards,
VJ
{!URLFOR('/lightning/o/Opportunity_Contact_Role__c/new?defaultFieldValues=Opportunity__c='&Opportunity__c.Id+'&backgroundContext=%2Flightning%2Fr%2FOpportunity_Contact_Role__c%2F'&Opportunity__c.Id+'%2Frelated%2FOpportunity_Contact_Roles__r%2Fview')}
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. :-)