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.
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.
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:
--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<soap:Body> inside the multipart wrapperThe parser fails at the first --uuid:... line and throws the 'Failed to get next element' exception.
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:
Content-Type: text/xml rather than Content-Type: multipart/related.If you do not control the external web service:
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.
000387950

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.