Created
May 13, 2020 07:21
-
-
Save sagivmalihi/4d8ab182b798934c28e6fe7089134edc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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