In the end it was sufficient for us to assume that the screen was being launched from the List View. If we need variations then I think we'll try to make a VF component and wrap that with different pages for different contexts. We'll cross that bridge when we come to it.
For now we have the following on the VF controller:
public String getReferer(){
Id filterId = setController.getFilterId();
String baseUrl = ApexPages.currentPage().getHeaders().get('Referer');
String fullUrl = baseUrl + 'one/one.app#/sObject/Contact/list?filterName=' + filterId;
return fullUrl;
}
In the VF we then pass a handler into the component when we construct it:
closePopoverHandler = function( event ) {
window.top.location = '{!referer}' ;
};
$Lightning.use( "c:OurLightningApp", function() {
$Lightning.createComponent( "c:OurLightningComponent",
{ param1: 'value1' },
"DivToReplace",
function(cmp) {
$A.eventService.addHandler({
event: 'force:closeQuickAction',
handler: closePopoverHandler
});
});
});
And then ensure that the LightningApp has the following dependancy:
<aura:dependency resource="markup://force:*" type="EVENT"/>
That said, as an alternative for finding the URL to return to - a more generic solution would be to use the ApexPages parameters, which sometimes contains the return url.
String retUrl = ApexPages.currentPage().getParameters().get('vfRetURLInSFX' );
if ( String.isNotEmpty( retUrl ) ) {
//
// the retUrl is in the parameters, so we should just return it
//
return retUrl;
}
//
// We can assume have been launched from a related list on an object, and so the url has to be constructed
//
String baseUrl = ApexPages.currentPage().getHeaders().get('Referer');
return baseUrl + 'one/one.app#/sObject/' + apexpages.currentpage().getparameters().get('id');
Best Answer
This got bumped up to the top... anyway there is now a way to do this as of Summer '18: Lightning Components that implement
lightning:isUrlAddressable
. See here: https://developer.salesforce.com/docs/component-library/bundle/lightning:isUrlAddressable/documentationYou can navigate to the URL and pass initial state parameters (including record ID) to get you started.