Salesforce Menu

SOAP Integration in Salesforce

Consuming SOAP API

In order to consume any SOAP APIs in salesforce, we need to get the WSDL file for that API. Once we have the WSDL file we need to go to Setup->Apex Classes->Generate from WSDL.

Select the WSDL file from your local system and upload it and click the Parse WSDL button.

If we don’t have any errors in the WSDL file (like the maximum size for WSDL files is 1 MB), then apex classes will be generated for this WSDL file. Name your apex class and click the Generate Apex Code button.

Once the apex class is generated, you will see the apex class contains some methods which can be called. For example, the sample WSDL file that we used contained a testSOAP method which looks something like this in the generated apex class :

public class MySOAPDemo {
        public String endpoint_x = '';
        public Map inputHttpHeaders_x;
        public Map outputHttpHeaders_x;
        public String clientCertName_x;
        public String clientCert_x;
        public String clientCertPasswd_x;
        public Integer timeout_x;
        public ExternalService.DebuggingInfo_element DebuggingInfo;
        public ExternalService.AllowFieldTruncationHeader_element AllowFieldTruncationHeader;
        public ExternalService.CallOptions_element CallOptions;
        public ExternalService.DebuggingHeader_element DebuggingHeader;
        public ExternalService.SessionHeader_element SessionHeader;
        private String DebuggingInfo_hns = 'DebuggingInfo=';
        private String AllowFieldTruncationHeader_hns = 'AllowFieldTruncationHeader=';
        private String CallOptions_hns = 'CallOptions=';
        private String DebuggingHeader_hns = 'DebuggingHeader=';
        private String SessionHeader_hns = 'SessionHeader=';
        private String[] ns_map_type_info = new 

String[]{'', 'ExternalService'};
        public String testSOAP(String str) {
            ExternalService.testSOAP_element request_x = new ExternalService.testSOAP_element();
            request_x.str = str;
            ExternalService.testSOAPResponse_element response_x;
            Map response_map_x = new Map();
            response_map_x.put('response_x', response_x);
              new String[]{endpoint_x,
            response_x = response_map_x.get('response_x');
            return response_x.result;

Now, we can simply call this method from this class to call to the third party service. Like this for example :

public class MySoapDemoCall
    public static void soapCallout()
        MySOAPDemo obj = new MySOAPDemo();
        String response = obj.testSOAP('SFDC');

Exposing SOAP API

Standard WSDL Files in Salesforce

In order to provide WSDL files used by salesforce for authentication (just like Connected Apps in REST Integration). Go to Setup-> API in your org.

You will see multiple types of WSDL files available, the most important of them are :

Enterprise WSDL

This WSDL file contains all the required information for the authentication process as well as all the metadata description from our org like objects, fields etc. Hence the size of this WSDL field will differ according to the metadata in your org.

Partner WSDL

This WSDL file contains all the necessary authentication methods but no metadata info, prefect if you just want to share an auth mechanism but not expose the metadata inside of your org.

Once you have chosen the correct WSDL file to use, you can click the Generate link next to the WSDL file and share that with the third party to use for authentication.

The WSDL will contain a login() method which will need to be called with a salesforce username and password to generate a session id.

The Webservice Keyword

If you need to expose any custom apex class via SOAP API or a WSDL file, we need to create a webservice method in our apex class.
Please note that in order to use the webservice keyword we need to have the method as global and static.

global class MySOAPDemo
    webservice static String testSOAP (String str)
        return 'Hello!!';

This is a very simple method which just returns a ‘Hello!!’ string. Once this class is created, we will see a generate WSDL above the apex class :

Click this button to generate a WSDL file for this class which will contain the ‘testSOAP’ method like this :

<binding name="MySOAPDemoBinding" type="tns:MySOAPDemoPortType">
<soap:binding style="document" transport=""/>
<operation name="testSOAP">
<soap:operation soapAction=""/>
<soap:header use="literal" part="SessionHeader" message="tns:Header"/>
<soap:header use="literal" part="CallOptions" message="tns:Header"/>
<soap:header use="literal" part="DebuggingHeader" message="tns:Header"/>
<soap:header use="literal" part="AllowFieldTruncationHeader" message="tns:Header"/>
<soap:body use="literal" parts="parameters"/>
<soap:header use="literal" part="DebuggingInfo" message="tns:Header"/>
<soap:body use="literal"/>

We can share this WSDL file with the third party application and they can call this apex class directly.

Calling this method with a WSDL file will return this output :

Subscribe Now