Spaces:
Build error
Build error
FIX: Correct bulk API usage for insert/update operations
Browse files
app.py
CHANGED
@@ -54,22 +54,19 @@ def salesforce_data_loader(username, password, security_token, sandbox, operatio
|
|
54 |
# Determine object based on columns (simple heuristic)
|
55 |
columns = df.columns.str.lower()
|
56 |
if any(col in columns for col in ['firstname', 'lastname', 'email']):
|
57 |
-
sf_object = sf_connection.Contact
|
58 |
object_name = "Contact"
|
59 |
elif any(col in columns for col in ['company', 'name']):
|
60 |
-
sf_object = sf_connection.Account
|
61 |
object_name = "Account"
|
62 |
else:
|
63 |
-
sf_object = sf_connection.Lead
|
64 |
object_name = "Lead"
|
65 |
|
66 |
-
# Perform operation
|
67 |
if operation == "insert":
|
68 |
-
result =
|
69 |
elif operation == "update":
|
70 |
-
result =
|
71 |
else:
|
72 |
-
return connection_msg + "❌ Invalid operation"
|
73 |
|
74 |
# Process results
|
75 |
success_count = sum(1 for r in result if r.get('success'))
|
|
|
54 |
# Determine object based on columns (simple heuristic)
|
55 |
columns = df.columns.str.lower()
|
56 |
if any(col in columns for col in ['firstname', 'lastname', 'email']):
|
|
|
57 |
object_name = "Contact"
|
58 |
elif any(col in columns for col in ['company', 'name']):
|
|
|
59 |
object_name = "Account"
|
60 |
else:
|
|
|
61 |
object_name = "Lead"
|
62 |
|
63 |
+
# Perform operation using bulk API correctly
|
64 |
if operation == "insert":
|
65 |
+
result = sf_connection.bulk.__getattr__(object_name).insert(cleaned_records)
|
66 |
elif operation == "update":
|
67 |
+
result = sf_connection.bulk.__getattr__(object_name).update(cleaned_records)
|
68 |
else:
|
69 |
+
return connection_msg + "❌ Invalid operation. Use 'insert' or 'update'"
|
70 |
|
71 |
# Process results
|
72 |
success_count = sum(1 for r in result if r.get('success'))
|