Skip to content

Instantly share code, notes, and snippets.

@sagivmalihi
Created May 13, 2020 07:21
Show Gist options
  • Save sagivmalihi/4d8ab182b798934c28e6fe7089134edc to your computer and use it in GitHub Desktop.
Save sagivmalihi/4d8ab182b798934c28e6fe7089134edc to your computer and use it in GitHub Desktop.
import json
from salesforce_api import Salesforce
client = Salesforce(
username=credentials['sf_username'],
password=credentials['sf_password'],
security_token=credentials['sf_security_token']
)
def dump_table(table_name, where=None):
print('analyzing table')
table_description = getattr(client.sobjects, table_name).describe()
fields = ', '.join([f['name'] for f in table_description['fields']])
query = f'select {fields} from {table_name} {"where" if where else ""} {where if where else ""}'
print(f'running query: {query}')
data = client.sobjects.query(query)
if where is None:
print(f'saving data to {table_name}.json')
json.dump(data, open(f'{table_name}.json', 'w'))
return data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment