Loading

'Failed to get next element' error in web service callouts

게시 일자: May 18, 2026
상세 설명

When making SOAP (Simple Object Access Protocol) web service callouts from Salesforce Apex, the following error may be returned:
System.CalloutException: Web service callout failed: Failed to get next element.
This error occurs when the external web service returns a multipart SOAP response — a response format (also called MIME Multipart/Related or MTOM — Message Transmission Optimization Mechanism) where multiple content blocks are combined into a single HTTP response body using boundary markers. Salesforce's SOAP response parser does not support this multipart response format and fails when it encounters the boundary markers instead of the expected XML structure.

솔루션

Root Cause

When Salesforce receives a response from an external SOAP web service, it attempts to parse the response body and deserialize it into the Apex classes that were generated from the web service's WSDL (Web Services Description Language) file. The parser expects the first XML node in the response body to be a <soap:Envelope> element (after any XML prolog, if present).
In a multipart SOAP response, the <soap:Envelope> is not the first element — instead, a multipart boundary marker (such as --uuid:...) appears first, followed by content-type and content-transfer headers. When the parser encounters this non-XML boundary marker, it throws the 'Failed to get next element' exception.

Example of a Multipart Response

The following is an example of the type of multipart SOAP response that causes this error. Note the --uuid:... boundary delimiters at the start and end of the response body, which indicate MTOM multipart packaging. The <soap:Envelope> is present but is preceded by these non-XML boundary elements, which the Salesforce SOAP parser cannot process.

11:12:06.213 (1213388226)|CALLOUT_RESPONSE|[111]|
--uuid:c71daf0b-eb0d-4aad-a8c3-6890e780e569
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml";
Content-Transfer-Encoding: binary
Content-ID: <root.message@cxf.apache.org>

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body>...</soap:Body></soap:Envelope>
--uuid:c71daf0b-eb0d-4aad-a8c3-6890e780e569--
11:12:06.213 (1213814277)|EXCEPTION_THROWN|[111]|System.CalloutException: Web service callout failed: Failed to get next element

In the example, you can see that the response contains:

  • A --uuid:... multipart boundary marker as the first element (instead of <soap:Envelope>)
  • Content-Type, Content-Transfer-Encoding, and Content-ID headers inside the multipart block
  • The actual <soap:Body> inside the multipart wrapper

The parser fails at the first --uuid:... line and throws the 'Failed to get next element' exception.

Solution

The recommended fix is to modify the external web service configuration to return a standard (non-multipart) SOAP response instead of a multipart response.
If you or your organization controls the external web service:

  • Disable MTOM (Message Transmission Optimization Mechanism) encoding in the service's configuration. MTOM is an optimization for binary attachments and is typically not needed for standard SOAP responses.
  • Configure the web service to return responses with Content-Type: text/xml rather than Content-Type: multipart/related.

If you do not control the external web service:

  • Contact the external web service provider or administrator and request that they disable multipart/MTOM responses for their service endpoint.
  • As a workaround, consider using Apex HttpRequest / HttpResponse classes for the callout instead of the WSDL-generated Apex stub, and manually parse the XML response to extract the <soap:Body> content.

 

Knowledge 기사 번호

000387950

 
로드 중
Salesforce Help | Article