Thursday, December 12, 2019

Extract Data from salesforce objects using python

Extract Data from salesforce  objects  using python:

we are trying to extract salesforce Lead object to csv.


import pandas as pd
from simple_salesforce import Salesforce

sf = Salesforce(
username='enter username',
password='password',
security_token='token from salesforce')

sf_data = sf.query_all("SELECT id, Email, FirstName, LastName, OwnerId ,Company, Address FROM Lead")
sf_df = pd.DataFrame(sf_data['records']).drop(columns='attributes')
print(sf_df['FirstName'])
sf_df.to_csv('sample3.csv', index=False)