+ Start a Discussion

Display in existing window with sidebar with PageReference puts page within page

I have a pretty simple Apex Controller + Action which I lifted from Salesforce Sidekick that takes a Flow, skins it up in Lightning Experience, and redirects to the newly created record. The issue I have is that when I use the flow launched from the button with a List Button with a Behavior = 'Display in existing window with sidebar' the final URL is not the true PageReference set in the action. The result is a page within a page showing the header and sidebar within the header and sidebar and the URL ends up looking like '/servlet/servlet.Integration?lid=...'

It works correctly and shows the page url as 'salesforce.com/RecordId' if I use the behavior = 'Display in existing window without sidebar or header' but I want to show the flow in an existing window and then have the PageReference just return to the new record. How can I accomplish this?

I have tried putting 'sidebar="false" showHeader="false"' in the header but it still doesn't work.

Thanks in advance!

Controller Code:
public with sharing class FlowRedirectController {

public Object FlowRedirectController() { 
    String unique_id    =       ApexPages.currentPage().getParameters().get('id');
    String obj          =       ApexPages.currentPage().getParameters().get('obj');

    if(unique_id == null){

        String url = '/home/home.jsp';
        return new PageReference(url);

    List<sObject> sobjList = database.query('SELECT Name, Unique_Flow_Identifier__c, Id  FROM '+String.escapeSingleQuotes(obj)+ ' WHERE Unique_Flow_Identifier__c = :unique_id ORDER BY CreatedDate DESC LIMIT 1');
    String returl = sobjList[0].id;

    if (returl == null) {
        // Return Home if no ID 
        String url = '/home/home.jsp'; 
    return new PageReference(url); }

    String url = '/' + returl;
        PageReference pRef = new PageReference(url);
    return pRef;}}

Visualforce page: 
<apex:page controller="FlowRedirectController" action="{!FlowRedirectController}" sidebar="false" showHeader="false">