Skip to content

Instantly share code, notes, and snippets.

@douglascayers
Last active December 31, 2020 16:55
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save douglascayers/1b103b1eb6e2dc8c167c8112ef686d36 to your computer and use it in GitHub Desktop.
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>
@douglascayers
Copy link
Author

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/

@vyhenderson
Copy link

"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