You need to sign in to do that
Don't have an account?
CalloutException in Reading Callout Response with Integer fields having null values
While calling a webservice from Salesforce, if the soap response has integer fields with null value, we get following error-
System.CalloutException: Web service callout failed: Failed to deserialize value '', due to:For input string: ""
The Request looked like -
<?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" <http://www.w3.org/2001/XMLSchema-instance> >
<env:Header/>
<env:Body>
<parameters xmlns="http://www.approuter.com/connectors/request/4/" <http://www.approuter.com/connectors/request/4/> >
<FEDERAL_TAXID>111111111</FEDERAL_TAXID>
</parameters>
</env:Body>
</env:Envelope>
The Response looked like -
<?xml version="1.0"?>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/" <http://schemas.xmlsoap.org/soap/envelope/> >
<Body>
<rows xmlns="http://www.approuter.com/connectors/response/4/" <http://www.approuter.com/connectors/response/4/> >
<row>
<Name>ABC Company</Name>
<MasterID>111111</MasterID>
<ParentCompany/>
<ParentTaxID/>
<TaxID>111111111</TaxID>
<TaxIDType>FedTaxID</TaxIDType>
<DateEstablished>2000-01-01T00:00:00.000</DateEstablished>
<GrossAnnualSalesYear/>
<GrossAnnualSales>100000</GrossAnnualSales>
<NoOfEmployee>30</NoOfEmployee>
<Website/>
<DUNSNumber>01234567</DUNSNumber>
<MajorityOwnershipEthnicityID>A99</MajorityOwnershipEthnicityID>
<MinorityOrWomenOwned/>
<WomenOwnershipPercent/>
<DiversityOwnershipPercent/>
<DBAName>ABC Connections</DBAName>
<FormerCompanyName/>
</row>
</rows>
</Body>
</Envelope>
In the above response GrossAnnualSalesYear, WomenOwnershipPercent and DiversityOwnershipPercent are integer fields which do not have values.
It gets resolved if we change the integer data returned by the webservice to always have some integer value.
It is only a temporary solution as it requires that we assume some value like in our case -1 as a value for NULL, since we are dealing with positive values only.
I am looking for a better solution or if it is a bug in the system, a fix from Salesforce.
Thanks.
Just an update to the initial problem - I have found that this problem exists for DateTime fields also. I have not yet verified for other types of fields but I think Salesforce is only able to deserialize String fields for now.
The element in the schema for Response, which is under consideration is as below-
<xs:element name="WomenOwnershipPercent" nillable="true" type="xs:integer">
<xs:annotation>
<xs:appinfo>
<app:node-app-info xmlns:app="http://www.approuter.com/schemas/2007/Mapping/AppInfo">
<app:node-name>WomenOwnershipPercent</app:node-name>
<app:node-description>Column Name</app:node-description>
</app:node-app-info>
</xs:appinfo>
</xs:annotation>
</xs:element>
<WomenOwnershipPercent/> is not schema valid according to that schema definition. If you want the value to be null, its needs to be <WomenOwnershipPercentage xsi:nil='true'/>