Integrating Salesforce with External Systems Using Apex SOAP and WSDL
🧩 Blog Outline:
Integrating Salesforce with External Systems Using Apex SOAP and WSDL
🧩 Blog Outline:
- Introduction
- What is SOAP & WSDL in the Context of Salesforce?
- Real-World Use Case
- Step-by-Step: Apex Integration Using WSDL
- Downloading the WSDL
- Generating Apex Classes
- Creating the Integration Logic
- Error Handling & Best Practices
5. Testing the Integration
6. Conclusion
7. Bonus Tips / Common Pitfalls
🔗 Integrating Salesforce with External Systems Using Apex SOAP and WSDL
Salesforce makes it easy to build modern web services, but integrating with legacy or enterprise systems often means dealing with SOAP APIs. In this guide, we’ll walk through how to consume external SOAP-based web services using WSDL and Apex in Salesforce — step by step.
Whether you’re integrating with a banking system, SAP, or a government service, this tutorial will give you the foundation you need.
📚 What is SOAP & WSDL in the Context of Salesforce?
- SOAP (Simple Object Access Protocol) is a protocol for sending structured XML data.
- WSDL (Web Services Description Language) is an XML-based document that describes the methods, parameters, and endpoints of a SOAP service.
Salesforce can generate Apex proxy classes from a WSDL file. These classes act like wrappers so you can call the external service with Apex code.
🧠 Use Case
Let’s say you’re working for a logistics company, and you need to integrate Salesforce with an external shipping provider. The provider exposes a SOAP API to create and track shipments, and they give you a ShipService.wsdl file.
🛠️ Step-by-Step: Calling a SOAP Service from Apex
1. Get the WSDL File
You’ll receive the WSDL from the third-party service provider. Make sure it’s complete and includes all dependencies.
2. Generate Apex Classes from WSDL
- Go to Setup > Apex Classes
- Click “Generate from WSDL”
- Upload your
.wsdlfile
Salesforce will auto-generate Apex classes representing the web service’s structure. Example:
public class ShipService {
public class CreateShipmentRequest { ... }
public class CreateShipmentResponse { ... }
webService class ShipPort {
webService static CreateShipmentResponse createShipment(CreateShipmentRequest request) {
...
}
}
}
3. Create Integration Logic
Now you can instantiate the web service class and call its methods:
ShipService.CreateShipmentRequest req = new ShipService.CreateShipmentRequest();
req.customerId = '12345';
req.destination = 'Austin, TX';
ShipService.ShipPort service = new ShipService.ShipPort();
ShipService.CreateShipmentResponse res;
try {
res = service.createShipment(req);
System.debug('Tracking Number: ' + res.trackingNumber);
} catch (Exception e) {
System.debug('Error: ' + e.getMessage());
}
4. Handle Authentication (if needed)
If the service requires a SOAP header for authentication, you may need to modify the generated Apex class and add a custom header manually.
Example:
public class AuthHeader {
public String token;
}
ShipService.ShipPort service = new ShipService.ShipPort();
service.inputHttpHeaders_x.put('Authorization', 'Bearer YOUR_TOKEN_HERE');
5. Use Named Credentials (Recommended)
For managing authentication securely, use Named Credentials in Salesforce instead of hardcoding tokens or endpoints.
🧪 Testing the Integration
Use Anonymous Apex or a test class with mock responses:
@isTest
global class MockShipResponse implements WebServiceMock {
global void doInvoke(...) {
// Return a fake tracking number
}
}
Assign the mock using Test.setMock() when writing unit tests.
✅ Best Practices
- Use Try-Catch for error handling.
- Monitor logs with Debug Logs or Platform Events.
- Avoid hardcoding URLs or tokens — use Custom Metadata or Named Credentials.
- If the WSDL changes, you’ll need to regenerate your classes.
🎯 Conclusion
SOAP might not be the most modern protocol, but it’s still common in enterprise systems. Luckily, Salesforce makes it relatively straightforward to work with via WSDL-generated Apex classes.
With this integration setup, you can interact with external systems reliably — sending data, triggering processes, or fetching results — all from within Salesforce.
💡 Bonus: Common Pitfalls
- Namespace conflicts in WSDL? Try cleaning up or renaming parts before import.
- Large WSDL files may need to be broken into smaller parts.
- Always check the API limits when working with synchronous calls.
메타데이터
- post_id
- 503ca4cda053
- slug
- integrating-salesforce-with-external-systems-using-apex-soap-and-wsdl-503ca4cda053
- url
- https://medium.com/@uussmmaann.y/integrating-salesforce-with-external-systems-using-apex-soap-and-wsdl-503ca4cda053
- canonical_url
- https://medium.com/@uussmmaann.y/integrating-salesforce-with-external-systems-using-apex-soap-and-wsdl-503ca4cda053
- author_url
- https://medium.com/@uussmmaann.y
- status
- ok
- fetched_at
- 2026-07-20 07:40:56