python - 对于 SalesForce API,这两个异常是什么意思?

标签 python api exception soap salesforce

我正在使用 SalesForce“Beatbox”库 (http://code.google.com/p/salesforce-beatbox/source/browse/trunk/src/beatbox/_beatbox.py)

异常 1:当我刚刚发送 leadId 时,我收到异常“INVALID_CROSS_REFERENCE_KEY:需要有效的 leadId”

这是说我没有使用有效的 leadId,但我发誓这是一个有效的 leadId,因为我事先检索了潜在客户并从 SalesForce 本身获取了 leadId!

异常(exception) 2: 当我取消注释 convertedStatus 和 doNotCreateOpportunity 参数时,出现异常“soapenv:Client fault: Element {urn:partner.soap.sforce.com}doNotCreateOpportunity 在此位置无效”

这表示我将参数传递给 SalesForce API 的方式有问题。不过在我看来它是正确的。

关于如何解决这些问题有什么想法吗?

def convertLead(self, leadIds, convertedStatus, doNotCreateOpportunity=False):
     return ConvertLeadRequest(self.__serverUrl, self.sessionId, leadIds, convertedStatus, doNotCreateOpportunity).post(self.__conn)


class ConvertLeadRequest(AuthenticatedRequest):
    """
    Converts a Lead to an Account. See also:
    http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_convertlead.htm
    """
    def __init__(self, serverUrl, sessionId, leadIds, convertedStatus, doNotCreateOpportunity=False):
        AuthenticatedRequest.__init__(self, serverUrl, sessionId, "convertLead")
        self.__convertedStatus = convertedStatus
        self.__leadIds = leadIds;
        self.__doNotCreateOpportunity = doNotCreateOpportunity


    def writeBody(self, s):
        #s.writeStringElement(_partnerNs, "convertedStatus", self.__convertedStatus)
        #s.writeStringElement(_partnerNs, "doNotCreateOpportunity", self.__doNotCreateOpportunity)
        s.writeStringElement(_partnerNs, "leadId", self.__leadIds)

编辑:

现在,当我提出以下请求时:

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:p="urn:partner.soap.sforce.com" xmlns:m="http://soap.sforce.com/2006/04/metadata" xmlns:o="urn:sobject.partner.soap.sforce.com" xmlns:w="http://soap.sforce.com/2006/08/apex" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <s:Header>
    <p:CallOptions>
      <p:client>BeatBox/0.9</p:client>
    </p:CallOptions>
    <p:SessionHeader>
          <p:sessionId>REDACTED</p:sessionId>
    </p:SessionHeader>
  </s:Header>
  <s:Body>
    <p:convertLead>
      <p:convertedStatus>Cold Qualified</p:convertedStatus>
      <p:doNotCreateOpportunity>False</p:doNotCreateOpportunity>
      <p:leadId>00QC000000zAbLEMA0</p:leadId>
      <p:overwriteLeadSource>False</p:overwriteLeadSource>
      <p:sendNotificationEmail>False</p:sendNotificationEmail>
    </p:convertLead>
  </s:Body>
</s:Envelope>

我仍然收到异常“转换后的状态无效”

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
    <soapenv:Fault>
      <faultcode>soapenv:Client</faultcode>
      <faultstring>Element {urn:partner.soap.sforce.com}convertedStatus invalid at this location</faultstring>
    </soapenv:Fault>
  </soapenv:Body>
</soapenv:Envelope>

最佳答案

问题是 writeBody 没有生成正确的结构。检查 WSDL 显示 convertLead 调用期望采用这些结构中的 0..n 个。 (异常(exception)#2 是关于此的提示)

    <element name="convertLead">
        <complexType>
            <sequence>
                <element name="leadConverts" type="tns:LeadConvert" minOccurs="0" maxOccurs="unbounded"/>
            </sequence>
        </complexType>
    </element>

    <complexType name="LeadConvert">
        <sequence>
            <element name="accountId"              type="tns:ID" nillable="true"/>
            <element name="contactId"              type="tns:ID" nillable="true"/>
            <element name="convertedStatus"        type="xsd:string"/>
            <element name="doNotCreateOpportunity" type="xsd:boolean"/>
            <element name="leadId"                 type="tns:ID"/>
            <element name="opportunityName"        type="xsd:string" nillable="true"/>
            <element name="overwriteLeadSource"    type="xsd:boolean"/>
            <element name="ownerId"                type="tns:ID"     nillable="true"/>
            <element name="sendNotificationEmail"  type="xsd:boolean"/>
        </sequence>
    </complexType>

所以你的 writeBody 需要像这样

def writeBody(self, s):
    s.startElement(_partnerNs, "leadConverts")
    s.writeElementString(_partnerNs, "convertedStatus", self.__convertedStatus)
    s.writeElementString(_partnerNs, "doNotCreateOpportunity", self.__doNotCreateOpportunity)
    s.writeElementString(_partnerNs, "leadId", self.__leadId)
    ...
    s.endElement()

如果您想进行批量潜在客户转换,那么您需要为每个要进行的潜在客户转换生成此结构的多个实例。

关于python - 对于 SalesForce API,这两个异常是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10358532/

相关文章:

Python:在给定索引值处将数据帧插入到更大的数据帧中

php - Facebook graph API,获取所有广告账户

ruby - 我怎样才能让这个 ruby 代码抛出异常并保释?

python - 如何将测试名称和模块添加到结果中的测试文档字符串?

python - 如何可靠地检测 python 文档字符串是否处于静止状态?

Python pandas dataframe 从列中选择行

api - 从 WSO2 Api Manager 检索用户访问 token

php - 通过 Graph API 将 Facebook 帖子创建为草稿

java - 如何停止在Java Sockets中第二次写入对象时出现streamcurrrupted异常

java - hibernate/ Spring 3 : could not initialize proxy - no Session