Closed GoogleCodeExporter closed 8 years ago
Hi,
the problem is that the responses you get on the partner-API are typeless, ie
dates, checkboxes etc are returned and interpreted as strings.
Consider below example from a retrieve (Test__c containing date__c, dateTime__c
and checkbox__c):
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:partner.soap.sforce.com" xmlns:sf="urn:sobject.partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<retrieveResponse>
<result xsi:type="sf:sObject">
<sf:type>Test__c</sf:type>
<sf:Id>a00d0000009gqHuAAI</sf:Id>
<sf:date__c>2013-02-01</sf:date__c>
<sf:dateTime__c>2013-02-01T19:43:51.000Z</sf:dateTime__c>
<sf:checkbox__c>false</sf:checkbox__c>
<sf:Id>a00d0000009gqHuAAI</sf:Id>
</result>
</retrieveResponse>
</soapenv:Body>
</soapenv:Envelope>
Note there are no type information on the sf:date__c etc.
When this response is used as source to create a new object using the
partner-API, eg:
SObject[] sObjects = connection.retrieve("date__c, dateTime__c, checkbox__c",
"Test__c", new String[]{ "a00d0000009gqHuAAI" });
SObject tst = new SObject();
tst.setType("Test__c");
tst.setField("Name", "Test 003");
tst.setField("date__c", sObjects[0].getField("date__c"));
tst.setField("dateTime__c", sObjects[0].getField("dateTime__c"));
tst.setField("checkbox__c", sObjects[0].getField("checkbox__c"));
SaveResult[] result = connection.create(new SObject[] { tst });
The following is sent in the create call:
<?xml version="1.0" encoding="UTF-8"?><env:Envelope
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Header>
<SessionHeader xmlns="urn:partner.soap.sforce.com">
<sessionId>xxx</sessionId>
</SessionHeader>
</env:Header>
<env:Body>
<m:create xmlns:m="urn:partner.soap.sforce.com" xmlns:sobj="urn:sobject.partner.soap.sforce.com">
<m:sObjects>
<sobj:type xsi:type="xsd:string">Test__c</sobj:type>
<sobj:Name xsi:type="xsd:string">Test 003</sobj:Name>
<sobj:date__c xsi:type="xsd:string">2013-02-01</sobj:date__c>
<sobj:dateTime__c xsi:type="xsd:string">2013-02-01T19:43:51.000Z</sobj:dateTime__c>
<sobj:checkbox__c xsi:type="xsd:string">false</sobj:checkbox__c>
</m:sObjects>
</m:create>
</env:Body>
</env:Envelope>
Note the xsi:type="xsd:string"on the date__c etc. This gives you a fault
because Salesforce does not try to convert datatypes.
If a similar "create" is done using Calendar as date/time and Boolean as
checkbox, the following is sent - which works:
<?xml version="1.0" encoding="UTF-8"?><env:Envelope
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Header>
<SessionHeader xmlns="urn:partner.soap.sforce.com">
<sessionId>xxx</sessionId>
</SessionHeader>
</env:Header>
<env:Body>
<m:create xmlns:m="urn:partner.soap.sforce.com" xmlns:sobj="urn:sobject.partner.soap.sforce.com">
<m:sObjects>
<sobj:type xsi:type="xsd:string">Test__c</sobj:type>
<sobj:Name xsi:type="xsd:string">Test 002</sobj:Name>
<sobj:date__c xsi:type="xsd:dateTime">2013-02-01T20:39:00.035Z</sobj:date__c>
<sobj:dateTime__c xsi:type="xsd:dateTime">2013-02-01T20:39:00.035Z</sobj:dateTime__c>
<sobj:checkbox__c xsi:type="xsd:boolean">true</sobj:checkbox__c>
</m:sObjects>
</m:create>
</env:Body>
</env:Envelope>
Note the xsi:type="xsd:dateTime" etc.
This is not part of the wsc tool. Your application must do the type conversion.
Original comment by jesperudby
on 2 Feb 2013 at 9:20
Original issue reported on code.google.com by
mlug...@simflofy.com
on 21 Sep 2012 at 9:43Attachments: