zhangjixing / sfdc-wsc

Automatically exported from code.google.com/p/sfdc-wsc
0 stars 0 forks source link

INVALID_TYPE_ON_FIELD_IN_RECORD #61

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create a custom test object in salesforce, in my case Test__c
2. Add date, datetime, checkbox fields
3. Download a record, copy all fields to a new SObject, try to update the 
record.

What is the expected output? What do you see instead?
Fields are updated.  Instead see this error message:

------------ Response start ----------
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns="urn:partner.soap.sforce.com" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><updateRespo
nse><result><errors><fields>DateTime__c</fields><message>DateTime: value not of 
required type: 
2005-10-14T15:09:00.000Z</message><statusCode>INVALID_TYPE_ON_FIELD_IN_RECORD</s
tatusCode></errors><id 
xsi:nil="true"/><success>false</success></result></updateResponse></soapenv:Body
></soapenv:Envelope>
------------ Response end   ----------
DateTime: value not of required type: 2005-10-14T15:09:00.000Z
INVALID_TYPE_ON_FIELD_IN_RECORD

What version of the product are you using? On what operating system?
Tested on:
wsc-22.jar
wsc-22-jdk-1.7.jar
API Version 25

Please provide any additional information below.

Attached is the soap being sent to salesforce and above you'll see the result 
of SavedResults from the connection.update cal.  Tested this on a bunch of 
different objects in the repo, always seems to fail on date, datetime, and 
checkboxes.  Does not fail on normal booleans or text fields though.

Original issue reported on code.google.com by mlug...@simflofy.com on 21 Sep 2012 at 9:43

Attachments:

GoogleCodeExporter commented 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