如何使用sforce或suds python库找到salesforce包前缀?

时间:2012-09-20 15:08:25

标签: python salesforce

我需要更新salesforce个对象的一些自定义字段。为此,我尝试使用upsert方法。我对选择模块感到困惑; SforceEnterpriseClient的{​​{1}}或SforcePartnerClient。我想我首先需要sforce的名称package prefix。我需要使用upsertsforce执行这些操作。对sudssforce技巧的一点解释会有所帮助。

1 个答案:

答案 0 :(得分:1)

你试过beatbox图书馆吗?它比salesforce-python-toolkit

简单

This is a full sample如何设置自定义字段:

import sys
import beatbox
import xmltramp
import datetime

sf = beatbox._tPartnerNS
svc = beatbox.Client()
class BeatBoxDemo:
        def login(self, username, password):
                self.password = password
                loginResult = svc.login(username, password)
                print "sid = " + str(loginResult[sf.sessionId])
                print "welcome " + str(loginResult[sf.userInfo][sf.userFullName])
        def upsert(self):
                print "\nupsert"
                t = { 'type': 'Task', 
                          'ChandlerId__c': '12345', 
                          'subject': 'BeatBoxTest updated', 
                          'ActivityDate' : datetime.date(2006,2,20) }

                ur = svc.upsert('ChandlerId__c', t)
                print str(ur[sf.success]) + " -> " + str(ur[sf.id])

                t = {   'type': 'Event', 
                        'ChandlerId__c': '67890', 
                        'durationinminutes': 45, 
                        'subject': 'BeatBoxTest', 
                        'ActivityDateTime' : datetime.datetime(2006,2,20,13,30,30),
                        'IsPrivate': False }
                ur = svc.upsert('ChandlerId__c', t)
                if str(ur[sf.success]) == 'true':
                        print "id " + str(ur[sf.id])
                else:
                        print "error " + str(ur[sf.errors][sf.statusCode]) + ":" +        str(ur[sf.errors][sf.message])

if __name__ == "__main__":

        if len(sys.argv) != 3:
                print "usage is demo.py <username> <password>"
        else:
                demo = BeatBoxDemo()
                demo.login(sys.argv[1], sys.argv[2])       
                demo.upsert()