Visualforce CSV Example. Note the 'contentType' page attribute and the # to specify the file name.
<!-- | |
This page must be accessed with an Account ID in the URL. | |
For example: https://<salesforceInstance>/apex/ContactsCsvPage?id=001D000000JRBet | |
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_styling_content_type.htm | |
--> | |
<apex:page standardController='Account' contentType='application/vnd.ms-excel#contacts.xls'> | |
<apex:pageBlock title='Contacts'> | |
<apex:pageBlockTable value='{!account.Contacts}' var='contact'> | |
<apex:column value='{!contact.Name}'/> | |
<apex:column value='{!contact.MailingCity}'/> | |
<apex:column value='{!contact.Phone}'/> | |
</apex:pageBlockTable> | |
</apex:pageBlock> | |
</apex:page> |
This comment has been minimized.
This comment has been minimized.
"contentType='application/vnd.ms-excel#contacts.xls". Excellent! It works! I appreciate your sharing! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Code snippet for my blog post about the many ways to export Salesforce data to CSV: https://douglascayers.com/2016/03/20/salesforce-easy-ways-to-export-data-as-csv/