SOAP Integration in Salesforce
If you don’t know the basics of SOAP fear not, because I've got you covered! Dive into the basics of SOAP with my latest blog, 'SOAP Explained: With JavaScript.’
Oh, you already know about SOAP and are here to learn how it works in Salesforce? You've come to the right spot! Let's get started.
SOAP Integration in Salesforce
SOAP is a protocol where client and server are tightly coupled meaning that minor changes on either side can potentially disrupt the connection.
To use SOAP API, your org must use Enterprise Edition, Performance Edition, Unlimited Edition, or Developer Edition. In all supported editions, a user must have the API Enabled permission turned on in the user profile they’re assigned.
In Salesforce, Apex SOAP web services(It is like a class) allow an external application to invoke Apex methods through SOAP Web services. The Web service that is available to you is defined in generated WSDL file.
What is WSDL?
Web Service Description Language is a file that defines all of the API calls, objects (including standard and custom objects), and fields that are available for API access for your organisation.
Salesforce provides two SOAP API WSDLs for two different use cases.
- Enterprise WSDL
- Partner WSDL
This API is mainly for people in big companies who are creating applications for their organisation.
The enterprise WSDL file is a strongly typed, It provides information about your schema, data types, and fields to your development environment, allowing for a tighter integration between it and the Lightning Platform Web service.
NOTE: This WSDL changes if custom fields or custom objects are added to, renamed, or removed from, your org’s Salesforce configuration.
This API is designed for Salesforce partners who are building applications for use across multiple organisations. The partner WSDL file is loosely-typed representation of the Salesforce object model, can be used to access data within any org.
Use Case: Typically, if you’re writing an integration for a single Salesforce org, use the enterprise WSDL. For several orgs, use the partner WSDL.
How to generate API WSDL file for org
Step1: Go to Setup, search for api
Step2: Generate wsdl file
Generate Apex Classes in external salesforce org
You can use the above-generated WSDL file to integrate an external system using any other language, such as Java, or you can use it to produce Apex classes in Salesforce (org which wants to communicate with source org’s SOAP API).
I've included an example at last of how these Apex classes will be used to access the SOAP API.
How to create SOAP web service in Source Salesforce org?
Use the webservice keyword to define Apex class methods to expose it as custom SOAP Web service. This allows an external application to invoke an Apex Web service to perform an action in Salesforce. See the following example:
global class SOAPWebService {
// SOAP Webservice
webservice static Id createContact(String contactLastName, String email) {
Contact c = new Contact(lastName = contactLastName, email = email);
insert c;
return c.id;
}
}
How to generate WSDL file for Class?
This WSDL file will be used
1. Setup > Apex Classes
You can create a soap callout now that you have developed the SOAP API in the source org and all the necessary classes in the external salesforce org.
Example of how to do SOAP callout in external salesforce org:
partnerSoapSforceCom.Soap myPartnerSoap = new partnerSoapSforceCom.Soap();
partnerSoapSforceCom.LoginResult partnerLoginResult = myPartnerSoap.login(<userName>,
<Password>+<SecurityToken>
);
soapSforceComSchemasClassSoapwebser.SessionHeader_element webserviceSessionHeader = new soapSforceComSchemasClassSoapwebser.SessionHeader_element();
webserviceSessionHeader.sessionId = partnerLoginResult.sessionId;
soapSforceComSchemasClassSoapwebser.SOAPWebService myWebservice = new soapSforceComSchemasClassSoapwebser.SOAPWebService();
myWebservice.SessionHeader = webserviceSessionHeader;
myWebservice.createContact('Ambani', 'mukesh@fakegmail.com');
Comments
Post a Comment