Webservice SOAP (salesforce)

Introduction

Unlike other technologies, as the JAX-WS JAVA API, SFDC does not provide any way to annotate how the WSDL should be generated.

Salesforce generated WSDLs tend to have, therefore, very low accuracy and usually be complex to understand.

WSDL and ID type

It's possible to use a SFDC 'ID' type anywhere in the interface of a webservice: Salesforce will automatically generate the type in the WSDL wihout any internal SFDC dependency:

<xsd:simpleType name="ID">

<xsd:restriction base="xsd:string">

<xsd:length value="18"/>

<xsd:pattern value="[a-zA-Z0-9]{18}"/>

</xsd:restriction>

</xsd:simpleType>

WSDL and enumerations

If an enumaration is declared and used in the webservice interface, SFDC will generate the WSDL with the corresponding xsd:simpleType:

global enum MyPlanet{Venus, Earth, Mars, Jupiter, Saturn, Uranus}

WSDL and collections of elements, eg: List

Usually, it is desired that all the elements of a collection are wrapped by tags that indicate the beginning and the end of them, eg: 'insureds' wrap two 'insured' elements:

<result>

<insureds>

<insured>

<birthdate>2000-12-31</birthdate>

<name>Ana García</name>

</insured>

<insured>

<birthdate>2000-12-31</birthdate>

<name>José Cuervo</name>

</insured>

</insureds>

<policyholder>Paweł Frącek</policyholder>

</result>

But SFDC does not, by default, generate the collection 'insureds' tag wrapper and therefore the result is:

<result>

<insureds>Ana García</insureds>

<insureds>José Cuervo</insureds>

<insureds>Mariana Mächler</insureds>

<policyholder>Paweł Frącek</policyholder>

</result>

Let's see a workaound to force Salesforce to generate wrapper tags for collection elements.

a) Our policy detail data object, dto, will hold an insurance policy number, its policyholder and the insurance list of insureds with their respective birthdates:

global class PolicyDetail{

webservice InsuredsWrapper insureds; //'insureds' will be the wrapper tag, therefore should be written in plural for clarity

webservice String policyholder;

webservice String policyNumber;

}

b) The wrapper dto will contain only one attribute, of type collection:

global class InsuredsWrapper{

webservice List<InsuredInfo> insured; //'insured' will contain the information of every single element, therefore written in singular

}

c) The InsuredInfo dto is used to hold the full name and birthdate of every single insured:

global class InsuredInfo{

webservice String name;

webservice Date birthdate;

}

d) The final result is very understandable, notice every single insured wrapped by tag 'insured' and all the insureds wrapped by tag 'insureds':

<result>

<insureds>

<insured>

<birthdate>2000-12-31</birthdate>

<name>Ana García</name>

</insured>

<insured>

<birthdate>2000-12-31</birthdate>

<name>José Cuervo</name>

</insured>

<insured>

<birthdate>2000-12-31</birthdate>

<name>Mariana Mächler</name>

</insured>

</insureds>

<policyholder>Paweł Frącek</policyholder>

<policyNumber>P27072</policyNumber>

</result>