function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vijay VadgamaVijay Vadgama 

Salesforce Lightning URL Hack - Cannot return to the original record after pressing "Save"

Hi everyone, 

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) after pressing the custom URL button. 

Here's a video example:
https://www.screencast.com/t/hrOkuHx4

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
EllEll
AFAIK you can't use retURL in this way off of a new record creation, as the action of saving a new record will always take you to the record created.

To get this functionality you could potentially use either a Visual Flow or custom Lightning Component, but you won't be able to do it just through standard button URLs
ANUTEJANUTEJ (Salesforce Developers) 
Hi Vijay,

You could additionally see the below idea that is currently open and to which you can upvote in case if you think this might be useful in the future.

>> https://trailblazer.salesforce.com/ideaView?id=08730000000JG82

I hope this helps and in case if this has come in handy can you please choose this as best answer so that it can be used by others in the future.

Regards,
Anutej