function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jim ZhanJim Zhan 

How to Create/Update SObject via ZSI?

I'm using ZSI ver2.0 to access Salesforce with partner.wsdl.xml, I can now use login/query/describe methods, but how can I create a Sobject to construct the creation request? I really have no idea about it. Here's the definition of Sobject & Create from the file I generated by using wsdl2py (with params: wsdl2py -ebf partner.wsdl.xml)

Code:
class sObject_Def(ZSI.TCcompound.ComplexType, TypeDefinition):
    schema = "urn:sobject.partner.soap.sforce.com"
    type = (schema, "sObject")
    def __init__(self, pname, ofwhat=(), attributes=None, extend=False, restrict=False, **kw):
        ns = ns0.sObject_Def.schema
        TClist = [ZSI.TC.String(pname=(ns,"type"), aname="_type", minOccurs=1, maxOccurs=1, nillable=False, typed=False, encoded=kw.get("encoded")), ZSI.TC.String(pname=(ns,"fieldsToNull"), aname="_fieldsToNull", minOccurs=0, maxOccurs="unbounded", nillable=True, typed=False, encoded=kw.get("encoded")), GTD("urn:partner.soap.sforce.com","ID",lazy=False)(pname=(ns,"Id"), aname="_Id", minOccurs=1, maxOccurs=1, nillable=True, typed=False, encoded=kw.get("encoded")), ZSI.TC.AnyElement(aname="_any", minOccurs=0, maxOccurs="unbounded", nillable=False, processContents="lax")]
        self.attribute_typecode_dict = attributes or {}
        if extend: TClist += ofwhat
        if restrict: TClist = ofwhat
        ZSI.TCcompound.ComplexType.__init__(self, None, TClist, pname=pname, inorder=0, **kw)
        class Holder:
            __metaclass__ = pyclass_type
            typecode = self
            def __init__(self):
                # pyclass
                self._type = None
                self._fieldsToNull = []
                self._Id = None
                self._any = []
                return
        Holder.__name__ = "sObject_Holder"
        self.pyclass = Holder

 Code:
class create_Dec(ZSI.TCcompound.ComplexType, ElementDeclaration):
    literal = "create"
    schema = "urn:partner.soap.sforce.com"
    def __init__(self, **kw):
        ns = ns1.create_Dec.schema
        TClist = [GTD("urn:sobject.partner.soap.sforce.com","sObject",lazy=False)(pname=(ns,"sObjects"), aname="_sObjects", minOccurs=0, maxOccurs="unbounded", nillable=False, typed=False, encoded=kw.get("encoded"))]
        kw["pname"] = ("urn:partner.soap.sforce.com","create")
        kw["aname"] = "_create"
        self.attribute_typecode_dict = {}
        ZSI.TCcompound.ComplexType.__init__(self,None,TClist,inorder=0,**kw)
        class Holder:
            __metaclass__ = pyclass_type
            typecode = self
            def __init__(self):
                # pyclass
                self._sObjects = []
                return
        Holder.__name__ = "create_Holder"
        self.pyclass = Holder

class createResponse_Dec(ZSI.TCcompound.ComplexType, ElementDeclaration):
    literal = "createResponse"
    schema = "urn:partner.soap.sforce.com"
    def __init__(self, **kw):
        ns = ns1.createResponse_Dec.schema
        TClist = [GTD("urn:partner.soap.sforce.com","SaveResult",lazy=False)(pname=(ns,"result"), aname="_result", minOccurs=0, maxOccurs="unbounded", nillable=False, typed=False, encoded=kw.get("encoded"))]
        kw["pname"] = ("urn:partner.soap.sforce.com","createResponse")
        kw["aname"] = "_createResponse"
        self.attribute_typecode_dict = {}
        ZSI.TCcompound.ComplexType.__init__(self,None,TClist,inorder=0,**kw)
        class Holder:
            __metaclass__ = pyclass_type
            typecode = self
            def __init__(self):
                # pyclass
                self._result = []
                return
        Holder.__name__ = "createResponse_Holder"
        self.pyclass = Holder 
any help will be appreciated.
 


Jim ZhanJim Zhan
The code I use to generate the SOAP message

Code:
SObject = ns0.sObject_Def("Contact").pyclass
client = SforceClient()
contact = SObject()
contact._type = "Contact"
contact._any.append({"FirstName": "Jim"})
contact._any.append({"LastName": "Zhan"})
contact._any.append({"Password__c": 123556})
contact._any.append({"NearestCapital__c": "Hongkong"})
result = client.create([contact])

SOAP message
Code:
<SOAP-ENV:Envalope
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ZSI="http://www.zolera.com/schemas/ZSI/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Header xmlns:ns1="urn:partner.soap.sforce.com">
<ns1:SessionHeader>
<ns1:sessionId>x7aLwfgfqX1StPgqSPHFcBlWtExZGt9A8QfyZUpwgDwQDLZYLMpRD7ppzhSg.Bq4L9A0zyusl0XVAxx9KI_YWQlOjj4TiJcRZe7PIt2o3SNUnm6BAJI=</ns1:sessionId></ns1:SessionHeader></SOAP-ENV:Header>
<SOAP-ENV:Body xmlns:ns1="urn:partner.soap.sforce.com">
    <ns1:create>
        <ns1:sObjects xmlns:ns2="urn:sobject.partner.soap.sforce.com" xsi:type="ns2:sObject">
            <ns2:type>Contact</ns2:type>
            <ns2:Id xsi:nil="1"></ns2:Id>
            <Eo1665300><FirstName xsi:type="xsd:string">Jim</FirstName></Eo1665300>
            <Eo1665c90><LastName xsi:type="xsd:string">Zhan</LastName></Eo1665c90>
            <Eo1669390><Password__c xsi:type="xsd:int">123556</Password__c></Eo1669390>
            <Eo1514030><NeareastCapital__c xsi:type="xsd:string">Hongkong</NeareastCapital__c></Eo1514030>
        </ns1:sObjects>
    </ns1:create>
</SOAP-ENV:Body></SOAP-ENV:Envelope>

Error
Code:
ZSI.FaultException: INVALID_FIELD: No such column 'Eo1665930' on entity 'contact'.
<SforceType.ApiFault_Holder object at 0x01773790>

 

 

 

Message Edited by Jim Zhan on 04-12-2007 09:18 PM