+ Start a Discussion
mjohnson-TICmjohnson-TIC 

Dynamic Visualforce Naming

I've been doing some work creating content in Visualforce that is rendered/opened in different formats (PDF, csv, excel etc). The few ways I have found to force rendering or download of the Visualforce page onload is to renderAs="PDF" or setting contenttype="text/csv" etc. The issue is during the load of the page, the page itself is saved using the naming convention of the Visualforce page, meaning you cannot specify the necessary extension. 

 

I was wondering if anyone had a workaround or any ideas to force the save of the page to a dynamic name and specify a file extension (for instance force a Visualforce page named Report with contenttype="application/csv" save as {dynamicname}.csv). 

 

My temporary work-around is having the file emailed as an attachment, as you can specify name of attachment and file extension dynamically in Visualforce templates. I would prefer the option to directly download rather then use this work-around. Anyone have any ideas?

Best Answer chosen by Admin (Salesforce Developers) 
aballardaballard

You may be able to get what you want by specifying the name in the contenttype.  Something like

 

contentType="text/csv#{!dynamicname).csv"

 

 

All Answers

aballardaballard

You may be able to get what you want by specifying the name in the contenttype.  Something like

 

contentType="text/csv#{!dynamicname).csv"

 

 

This was selected as the best answer
mjohnson-TICmjohnson-TIC

Awesome. thanks - that worked!

maxforcemaxforce

Hi, I have the similar requirement to save an output document that renderas PDF with a dynamic name. I tried using  contentType="application/pdf#{!XXXXX.Name}.pdf" but it didn't work. Any suggestions?

DikshantDikshant

Hello Maxforce, did you find a solution to this naming problem? I have a similar problem.

maxforcemaxforce

Hi Dikshant,

 

No I didn't find a solution, but I did a work around by directly attaching the PDF doc to the Attachments section when the user clicks on the button with the required naming convention.

maxforcemaxforce

Hi Dikshant,

 

I got the solution. You should not used renderAs="PDF"  in the apex:page tag, you should use only contentType="application/pdf#{!NOW()}". But if you don't use renderAs it will not open the pdf, instead it will save directly in your system with the Dynamic name. Try it.