Rukgo
Rukgo

Reputation: 121

Saving Salesforce Report Data to CSV

I am currently using the code below to go out and fetch a Salesforce report and try to write it to a csv file. When I take the length of items its 2000, but when I execute this code it produces a CSV file that only contains 55 rows total. My guess is something is off in the write function but I am unsure.

Anyone suggestions would be appreciated.

import csv
from salesforce_reporting import Connection
import salesforce_reporting
sf = Connection(username='user',password='pw',security_token='token')
report = sf.get_report('report_id',details=True)
parser = salesforce_reporting.ReportParser(report)
items = parser.records()
with open("output.csv", "w") as f:
   writer = csv.writer(f)
   writer.writerows(items)

Upvotes: 0

Views: 957

Answers (1)

Rukgo
Rukgo

Reputation: 121

I was able to figure out that the issue was indeed in the writing aspect of my code. The code below will export your report without headers.

import csv
from salesforce_reporting import Connection
import salesforce_reporting

sf = Connection(username='user',password='pw',secrity_token='token')
report = sf.get_report('reportid',details=True)
parser = salesforce_reporting.ReportParser(report)
items = parser.records()
f = csv.writer(open('test_output.csv','w'))
f.writerows(items)

Upvotes: 1

Related Questions