I already tried to generate a csv of my list by create a separate vf page with the page attribute
contentType="text/csv#Export.csv"
Is that possible to generate and download a csv on the fly without using "contentType="text/csv#Export.csv"
Attribution to: Bforce
Possible Suggestion/Solution #1
You do need the contentType, but they can be rolled into one page. You can use a merge field to control which output to use. For example:
<apex:page controller="listpage" contentType="{!contentType}">
<!-- your content here, rendered based on content type... -->
<apex:form rendered="{!contentType='text/html'}">
<apex:commandButton value="Export" action="{!export}" />
</apex:form>
</apex:page>
And the controller:
public class listpage {
public string contentType { get; set; }
public listpage() {
contentType = 'text/html';
}
public void export() {
contentType = 'text/csv#export.csv';
}
}
NOTE You'll need to do more than just this to make sure the headers are not emitted, etc based on the content type. It may be easier to just use a separate page, but it's certainly possible to make it a single page.
Attribution to: sfdcfox
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/34852