How do developers expose custom Apex business logic as a SOAP web service for legacy enterprise consumers?
Answer
Basics: Apex SOAP services serve legacy systems that only speak SOAP/WSDL. You write ordinary Apex, add the webservice keyword to a static method, and Salesforce creates the SOAP operation and contract. Newer integrations should prefer Apex REST, but SOAP remains valid for legacy consumers.
How it works:
- Write
global with sharing class OrderServiceand awebservice staticmethod. - Open Setup > Apex Classes > the class > Generate WSDL (the button appears for classes with webservice methods).
- Give the consuming system the WSDL; it generates client stubs.
- The client authenticates (OAuth access token or session ID) and sends it in a
SessionHeader, then posts to/services/Soap/class/<ClassName>. - Salesforce runs the method and returns an XML response.
- Grant the integration user access to the Apex class.
Advanced / deep dive: Method parameters and return types are limited to types SOAP can describe: primitives, sObjects, lists, and user-defined global inner classes with webservice fields. Maps and Sets are not allowed in the signature and methods cannot be overloaded, so design with List wrappers. The same Apex governors apply; there is no extra bulk behavior, so accept List<> input to let callers batch and avoid per-record calls. Sharing is controlled by the class keyword; FLS is not enforced automatically for DML in Apex. Because the WSDL is a contract, changing a signature breaks clients; prefer adding new methods or a new class for new versions. You can also consume external SOAP services from Apex using WSDL2Apex (Setup > Apex Classes > Generate from WSDL), which is the reverse direction.
Code / config example: