英文:
dot notation and accessing module functions using strings
问题
对于你的代码问题,你可以尝试使用以下解决方法:
objectName = "Account"
sf.bulk[objectName].upsert(dataToSalesforce, externalIdField, batch_size=10000)
这个修改应该能够解决你的问题。它允许你使用变量 objectName
作为对象的名称来执行 upsert
操作,而不会将其解释为字符串 "objectName"。这样,你可以动态地更改 objectName
的值以适应不同的对象。
英文:
pretty new to python, so i tried googling around for answers but i was probably googling the wrong terminology.
So here's my problem
i have this
objectName ="Account"
sf.bulk.objectName.upsert(dataToSalesforce,externalIdField, batch_size=10000)
The above command should send an upsert request for salesforce upserting on the account object, but it gives me the error {'exceptionCode': 'InvalidJob', 'exceptionMessage': 'Unable to find object: objectName'}
the problem is it tried to query the object objectName and not Account.
Everything works fine when i use: sf.bulk.Account.upsert(dataToSalesforce,externalIdField, batch_size=10000)
but in the current use case the object being upserted to may change.
答案1
得分: 0
当查看错误时,我注意到它使用了术语“attribute”,并在使用该术语进行谷歌搜索时,我发现我可以这样做
getattr(sf.bulk, objectName).upsert(dataToSalesforce, externalIdField, batch_size=10000, use_serial=True)
这解决了问题。
英文:
When looking at errors I noticed it used the term attribute, and googling using that term I found I could do this
getattr(sf.bulk, objectName).upsert(dataToSalesforce, externalIdField,batch_size=10000, use_serial=True)
that solves the issue.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论