Adding my late 2019/ early 2020 experience to thread for others that land here from searching...
'CF' page parameters and the '_lkid':
Project for client required solution for a related list (--child junction object). So requirement is override New action on related list. Right now using VF page with a controller.
Solution works by assigning
to a map and looping through keyset() of this map looking for the 'CFxxxxxxx_lkid' pattern. The _lkid parameter value is the recordid of the junction object relationship --essentially the parentId of the relation to the child (of the related List). This parameter populates the saveURL parameter. The xxxxxx value will vary based on Org and relationships but it is the id of the relationship name. Here is how this _lkid parameter looks in my project: CF00N0r0000016cCV_lkid.
For ORG 'safety', instead of hardcoding the CF parameter using
I assign page parameters to a map:
Map<String, String> urlParams = ApexPages.CurrentPage().getParameters();
for (String key: urlParams) loop through the map key looking for
key.endsWithIgnoreCase('_lkid') pattern. When found assign the value to controller variable for object record.
In my controller, related custom object is
docObj and target related field is
part__c will have the parentId, so
docObj.part__c = urlParams.get(key). After Save operation, new related record will have its Record Id and part__c with correct value to make the relation to parent --from the _lkid.
CAUTION is to assign
APEXPAGE.currentpage.getparameters() to map variable in Controller Constructor early to store all of them. I experienced the 'BlackBox' nature of SF ops, the parameters values seem to be volatile and go 'dark' (null) if too much happens in controller before inspecting them.
Another 'dang' moment is after Save, retURL takes you back to detail record but related list is not refreshed. You have to force refresh of detail page in the save operation return with PageRefrence
New related list record (VF v. LEX):
I override the custom object's new action with a VF page (object's setup Buttons, Links, Actions). I designed the VF page to be 'popover modal' styled to mimic SF UX but Salesforce pushes the VF page into a different domain and uses an iframe so the parent detail page falls out of view and replaced by iframe empty background. VF page's APEX:Form is positioned in middle with CSS. It sort-of feels like SF UX but still makes you go 'dang SF, really?' because VF is in iframe 'jail'. The Cancel button for NEW action in VF page uses the page parameter retURL.
Still working on the LEX controller.
Hope this helps.