+ Start a Discussion
mandycmandyc 

Call URL from custom button without leaving page

Hello,

 

The below code was written by someone else and basically it's constructing a URL to a page that downloads a file. Generate() is called by a button click on a VF page. After the button is clicked the user is presented with a white/blank browser page while the file is downloaded. The user then has to click the browser back button to return to the page they clicked the button. I would prefer to have the user stay on the Salesforce page when the button is clicked and have the file download. Any ideas what I might try?

 

The custom button was set to open in a new window and I changed it to display in current window with sidebar. The URL for the button is /apex/ReportParm?Id={!Custom_Reports__c.Id}&Name={!Custom_Reports__c.Name}&URL={!Custom_Reports__c.Report_URL__c}

 

Note, the sidebar does not display when the button is clicked...just a blank, white screen.

 

public class CustomReports_Extension 
{
    Transport__c transport;
    
    string strReportId;
    string strReportName;
    string strURL;
    string strPath;
    integer parmNum;
    string errorMessage;
    
    Report_Parameters__c parms_1;
    Report_Parameters__c parms_2;
    Report_Parameters__c parms_3;
    Report_Parameters__c parms_4;
    Report_Parameters__c parms_5;
    
    List<string> multiPickList_1 = new List<string>();
    List<string> multiPickList_2 = new List<string>();
    List<string> multiPickList_3 = new List<string>();
    List<string> multiPickList_4 = new List<string>();
    List<string> multiPickList_5 = new List<string>();
    
    public CustomReports_Extension(ApexPages.StandardController controller) 
    {
        this.transport = new Transport__c();

        strReportId = System.currentPageReference().getParameters().get('Id'); 
        strReportName = System.currentPageReference().getParameters().get('Name');
        strURL = System.currentPageReference().getParameters().get('URL'); 
        
        List<Report_Parameters__c> parms = new List<Report_Parameters__c>();

        parms = [SELECT Parameter_Label__c, Parameter_Order__c, Name, Render_Text__c, 
                    Render_Date__c, Render_Checkbox__c, Render_Select_List__c, Render_Multi_Select_List__c 
                 FROM Report_Parameters__c WHERE Report_Number__c = :strReportId ORDER BY Parameter_Order__c];

        parmNum = parms.size();
    }
    
    public CustomReports_Extension(Transport__c transporter) 
    {
        this.transport = transporter;
        
        strReportId = System.currentPageReference().getParameters().get('Id');
        strReportName = System.currentPageReference().getParameters().get('Name');
        strURL = System.currentPageReference().getParameters().get('URL'); 
        
        List<Report_Parameters__c> parms = new List<Report_Parameters__c>();

        parms = [SELECT Parameter_Label__c, Parameter_Order__c, Name, Render_Text__c, 
                    Render_Date__c, Render_Checkbox__c, Render_Select_List__c, Render_Multi_Select_List__c  
                 FROM Report_Parameters__c WHERE Report_Number__c = :strReportId ORDER BY Parameter_Order__c];

        parmNum = parms.size();
    }

    public PageReference ParameterCheck()
    {
        string strPath;
        PageReference thisPage;
        
        if (parmNum == 0) //NO PARAMETERS NEEDED
        {
            strPath = strURL;
            thisPage = new PageReference(strPath); 
            thisPage.setRedirect(true);
        }
    
        return thisPage;
    }    

    public pageReference generate()
    {
        string strParmValues = ''; 
        string strParmName = '';
        
        if (parmNum == 0)
        {
            strPath = strURL;
        }
        else
        {
           //PARM 1
           if (parms_1.Render_Text__c == True)
           {
                if (Transport.Name_1_40__c == '' || Transport.Name_1_40__c == ' ')
                {
                    PageReference thisPage = page.ReportParm;
                    thisPage.setRedirect(false);
                    setError();

                    return thisPage;
                }
                else
                {
                    strParmValues = parms_1.Name + '=' + Transport.Name_1_40__c;
                }
           }                   
        }     
        strPath = strURL + '?' + strParmValues;

        PageReference thisPage = new PageReference(strPath);  
        thisPage.setRedirect(true);

        return thisPage;
    }
}

 Thank you.

 

Saikishore Reddy AengareddySaikishore Reddy Aengareddy

update

 

thisPage.setRedirect(true);

 

to

 

thisPage.setRedirect(false);

mandycmandyc

Thanks. I tried your suggestion but it didn't change the behavior.

Saikishore Reddy AengareddySaikishore Reddy Aengareddy

There are couple of places where it says setredirect(true)... have you updated in both the places? 

 

I have close to similar fuctionality that you have and it works well for me with setRedirect(false)..

mandycmandyc

Good point, I hadn't updated all the references. Unfortunately, after changing all the references from true to false I still get the same behavior of the white/blank screen.