Reputation: 748
I am using the simple-salesforce python package with python 3. According to the documentation, I should be able to bulk update records using this syntax:
data = [{'Id': '0000000000AAAAA', 'Email': '[email protected]'}, {'Id':'0000000000BBBBB', 'Email': '[email protected]'}]
sf.bulk.Contact.update(data)
However the instance of simple-salesforce that I implemented does not recognize
sf.bulk.Custom_Object__c
When I try to execute:
sf.bulk.Custom_Object__c.update(data)
I get this error:
AttributeError Traceback (most recent call last)
<ipython-input-126-b287358940fc> in <module>()
----> 1 sf.bulk.Custom__bject__c.update(data)
AttributeError: 'SFType' object has no attribute 'Custom_Object__c'
Has anyone else worked with the simple-salesforce python package and run into this issue before?
Upvotes: 4
Views: 3811
Reputation: 89
You should use Salesforce()
function to login instead of SFType()
. Here an example:
import pandas as pd
from simple_salesforce import Salesforce
sf = Salesforce(username='my_username', password='my_password', security_token = 'my_token', domain = 'login')
In case you are using pandas
to manage your data, you will need to convert your df
to a list of dictionaries using df.to_dict('records')
method before the update.
fake_df = pd.DataFrame({'Id': ['rowID1', 'rowID2'], 'CustomField__c':[1,2]})
fake_dict = fake_df.to_dict('records')
Although you could use sf.bulk.MyCustomObject__c
to set the name of the SFDC object to be updated, I prefer sf.bulk.__getattr__(objectName)
so you can reuse the code in a function and easily switch objects.
objectName = 'MyCustomObject__c'
results = sf.bulk.__getattr__(objectName).update(fake_dict, batch_size = 10000)
Upvotes: 1
Reputation: 722
I use sf.bulk.Custom_Object__c.update(data)
regularly and have never encountered this issue. I would suggest trying out the following troubleshooting methods:
sf = Salesforce(password=userPassword, username=userName, organizationId=orgId)
) is bringing you into the correct org (that your orgId
is correct)SalesforceMalformedRequest
error rather than a Attribution
error, and it is possible you are using an out-of-date version of Simple-SalesforceUpvotes: 0