7

What does properly formed XML look like when attempting to pass in a null value for a number field?


Let's say I have a SOAP endpoint defined as follows:

webservice static void save(MyObject__c record)
{
    // fancy upsert logic here
}

And my payload comes in looking like:

<soapenv:Envelope ...>
    <soapEnv:Header>
        <!-- header info -->
    </soapEnv:Header>
    <soapenv:Body>
        <ns0:save>
            <ns0:myObjectData>
                <ns0:Number_Field__c/>
                <!-- other fields -->
            </ns0:myObjectData>
        </ns0:save>
    </soapenv:Body>
</soapenv:Envelope>

The above payload is trying to save a record with Number_Field__c=null. Unfortunately, the endpoint generates this error message:

'' is not valid for the type xsd:double

Entire response:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <soapenv:Fault>
         <faultcode>soapenv:Client</faultcode>
         <faultstring>'' is not valid for the type xsd:double</faultstring>
      </soapenv:Fault>
   </soapenv:Body>
</soapenv:Envelope>

To reiterate: What does properly formed XML look like when attempting to pass in a null value for a number field?

1
  • 1
    Not nearly experienced enough with xml/SOAP to give a proper answer, but I've seen xml errors reference something of the form xsi:nil before, and a cursory search indicates that this can be an attribute of an xml tag.
    – Derek F
    Commented Jun 8, 2018 at 1:13

1 Answer 1

4

You should be able to specify null with xsl:nil:

<ns0:Number_Field__c xsl:nil="true" />
4
  • Will let you know results when I get them. Might be a day or few.
    – Adrian Larson
    Commented Jun 8, 2018 at 1:19
  • @AdrianLarson Sure. By the way, this seems to be true in the AJAX toolkit, by reading the source code, so I'm pretty sure this is right.
    – sfdcfox
    Commented Jun 8, 2018 at 1:20
  • Excellent. Yeah it looks right, just couldn't produce it on my own.
    – Adrian Larson
    Commented Jun 8, 2018 at 1:21
  • 2
    Also, check that you have a xmlns:xsl="http://www.w3.org/2001/XMLSchema-instance" attribute somewhere earlier in the xml to define the namespace prefix. Commented Jun 8, 2018 at 2:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .