Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Apex CSV Example. Note the use of String.escapeCsv() method
String csv = 'Id,Name\n';
for ( List<Account> accts : [ SELECT id, name FROM Account LIMIT 10 ] ) {
for ( Account acct : accts ) {
csv += + ',' + + '\n';
ContentVersion file = new ContentVersion(
title = 'accounts.csv',
versionData = Blob.valueOf( csv ),
pathOnClient = '/accounts.csv'
insert file;
System.debug( file );

This comment has been minimized.

Copy link
Owner Author

douglascayers commented Jan 2, 2017

Code snippet for my blog post about the many ways to export Salesforce data to CSV:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.