-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdescribe_object.py
85 lines (63 loc) · 2.05 KB
/
describe_object.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import logging
import pprint
import sys
from simple_salesforce import Salesforce
from tqdm import tqdm
from utils import salesforce_login as login
logging.basicConfig(format="%(asctime)s : %(message)s", level=logging.ERROR)
#
# sf_credentials = (
# "<instance_url>",
# "<session_id>",
# )
#
sf_credentials = (
"",
"",
)
exclude = ["fHCM2__", "fRecruit__"]
def describe_object(sf: Salesforce):
custom_objects = []
s_err = []
s_out = []
describe_response = sf.describe()
for sobj in describe_response["sobjects"]:
if (
sobj["custom"]
and sobj["name"][-3:] == "__c"
and not any(substring in sobj["name"] for substring in exclude)
):
custom_objects.append({"name": sobj["name"]})
if custom_objects:
pbar = tqdm(total=len(custom_objects), desc="sf", ncols=100)
for row in custom_objects:
pbar.update(1)
try:
describe_response = sf.__getattr__(row["name"]).describe()
for field in describe_response["fields"]:
s_out.append(
{
"sobject": row["name"],
"field": field["name"],
"type": field["type"],
"length": field["length"],
"externalId": field["externalId"],
"unique": field["unique"],
}
)
except Exception as e:
s_err.append({"sobject": sobj["name"], "error": e})
raise
pbar.close()
for msg in s_out:
pretty = pprint.pformat(msg, indent=2, width=80)
print(f"\n{msg}")
for message in s_err:
logging.error(f"ERROR ~ {str(message['error']).strip()}")
if __name__ == "__main__":
sf = login(sf_credentials)
if not sf:
print("\n*** Not Logged into Salesforce ***\n")
sys.exit(1)
print("\n*** Logged into Salesforce ***\n")
describe_object(sf)