I have a Visualforce page that is launched from an action on a custom object (Plate), and it exports a report as a CSV file with the Plate Name in the exported file name(this is the reason I used Visualforce, since I couldn't find a way to include the Plate Name in the file name any other way).

Here's my issue

When I click the button on the Plate record, the CSV download happens and the file name is correct. BUT, it routes me to a blank screen (see screenshot) and I need it to either (1) automatically route me back to the Plate record, or (2) give me a button to route me back to the Plate record.

You can see that I have a button component in the VF code below but it doesn't render on the screen. This is very much piecemealed together from templates I found (I'm not a coder but can manipulate templates to a certain extent), so I really don't know if this is the route I should be taking anyway. Open to any/all suggestions.

screenshot of rendered vf page

The requirements are:

  • Must click a button or link from the Plate record that exports data from a report (or it could be a soql query CSV export, but the report export is what I went with)
  • the report has several static filters and one dynamic filter (pv0 = Plate ID)
  • the CSV export must have the Plate Name in it (e.g. Report_Plate_10050)
  • the report could return up to 100 rows, but not likely more than that (FYI in case there are limitations with whatever solutions are proposed)

Here's what I've got:

Button URL on Plate object:


APEX Controller:

Public class ddPCRDownload{
    private ApexPages.StandardController ctrl;
    public Plates__c plates {get {
            plates=[select id,name from plates__c where id=:this.ctrl.getId()][0];
        return plates;
    } private set;}
    public ddPCRDownload(ApexPages.StandardController ctrl) {
       this.ctrl = ctrl;    }
    public PageReference downloadReport() {
      String reportId = '00ODS000002IHCb2AO';
      PageReference reportPage = new PageReference('/' + reportId + '?xf=csv&export=1&enc=UTF-8&isdtp=p1&pv0='+this.plates.name);
     return reportPage;

Visualforce Page:

<apex:page standardcontroller="Plates__c" extensions="DownloadCSVReport" showHeader="false" showChat="false" contentType="application/vnd.ms-excel#{!$Request.fileName}">
<apex:form >
   <apex:commandbutton value="Back to Plate" 
        action="{!URLFOR($Action.Plates__c.View,Id)}" rendered="true">      



You must log in to answer this question.

Browse other questions tagged .