Advanced 15 min read

SOAP Callouts and WSDL2Apex

By the end of this lesson, you'll be able to:

  • Explain what WSDL2Apex generates and why it's needed for SOAP callouts
  • Call a method on a generated SOAP client stub

Prerequisites: Securing Callouts with Named Credentials

Why WSDL2Apex instead of hand-built XML

SOAP messages are strict, verbose XML defined by a WSDL (Web Services Description Language) file. Rather than hand-crafting that XML, Setup's WSDL2Apex tool reads a WSDL and generates a matching set of Apex classes — a client stub class, plus classes for every request/response type — so you interact with a SOAP service the same way you'd call any other Apex method.

Calling the generated stub

After import, instantiate the generated service class and call its method directly — the generated code handles building and parsing the SOAP envelope behind the scenes, entirely out of view.

Calling a generated SOAP stub

ExampleSoapService.ExampleServicePort service = new ExampleSoapService.ExampleServicePort();
service.timeout_x = 10000;

String result = service.getCustomerName('CUST-001');
System.debug(result);

ExampleSoapService.ExampleServicePort is generated code, produced by pasting the SOAP service's WSDL into Salesforce's WSDL2Apex tool — you never write the SOAP envelope by hand.

Exercise

In a comment, describe the two steps needed before you can call a SOAP method from Apex.

Show hint

Think about what has to happen in Setup before any Apex code can run.

APEX

SOAP Callouts and WSDL2Apex — Quick Check

1. What does Salesforce's WSDL2Apex tool generate?

2. Apex developers typically hand-write the raw SOAP XML envelope for each callout.

3. What do you call on a generated SOAP client stub to invoke the service?

Log in to submit the quiz and save your score.

My Notes

Log in to keep private notes on this lesson.

Questions about this lesson

No questions yet — be the first to ask.

Log in to ask a question about this lesson.

Summary

SOAP integrations are still common with older enterprise systems. Salesforce doesn't let you hand-build SOAP XML — instead, you import a WSDL file via Setup's WSDL2Apex tool, which generates Apex classes representing the SOAP service, and you call methods on those generated classes like any other Apex object.