function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

external web services through apex

Hi all-


I'm wondering if anybody knows a good place to start finding ways to access and execute an external web service using Apex.  Any help is appreciated!!



The apex docs includes a section on calling external services.

Thanks, Simon!


I found the documentation, and I followed it, but I'm running into some issues and I'm wondering if anybody can help.


I have a method I'm trying to consume 


 public void CreateNewAccount() {


csCallCenterWS.csCallCenterSoap csWebHost = new csCallCenterWS.csCallCenterSoap();csCallCenterWS.CreateNewAccountResult_element result = csWebHost.CreateNewAccount(Username, Password, 310201, 'FRANK', 'SINATRA', 'SINATRA, FRANK', '295', '123', '123', 'SPRINGFIELD', 'IL', '90210', 'TEST@EXAMPLE.COM', '111-111-1111');




Here is the method inside the "DocSamplePort"...


 public csCallCenterWS.CreateNewAccountResult_element CreateNewAccount(String strUser,String strPin,Integer lngSiteID,String strFirstName,String strLastName,String strAccountName,String strAccountType,String strAddress1,String strAddress2,String strCity,String strState,String strZip,String strEmail,String strHomePhone) {csCallCenterWS.CreateNewAccount_element request_x = new csCallCenterWS.CreateNewAccount_element();

csCallCenterWS.CreateNewAccountResponse_element response_x;

request_x.strUser = strUser;

request_x.strPin = strPin;

request_x.lngSiteID = lngSiteID;

request_x.strFirstName = strFirstName;

request_x.strLastName = strLastName;

request_x.strAccountName = strAccountName;

request_x.strAccountType = strAccountType;

request_x.strAddress1 = strAddress1;

request_x.strAddress2 = strAddress2;

request_x.strCity = strCity;

request_x.strState = strState;

request_x.strZip = strZip;

request_x.strEmail = strEmail;

request_x.strHomePhone = strHomePhone;

Map<String, csCallCenterWS.CreateNewAccountResponse_element> response_map_x = new Map<String, csCallCenterWS.CreateNewAccountResponse_element>();response_map_x.put('response_x', response_x);





new String[]{endpoint_x,








response_x = response_map_x.get('response_x'); return response_x.CreateNewAccountResult;




When I run the code I get this error...


"System.CalloutException: Web service callout failed: Unable to parse callout response. Apex type not found for element CreateNewAccount"

Does anybody know how I can find out what the issue might be?

The SOAP response from the service included a CreateNewAccount xml element, and that element was not present in the WSDL description of the service, so it doesn't know what do with it. You need to ensure that the WSDL correctly describes the messages returned by the service.

Ok. That's what I thought.  So, how do I ensure that the WSDL has the response defined correctly?  There are two responses that come back.  A success and an error with different nodes depending on the type.  Is there any documentation that explains how to code this in the WSDL?


PS - I'm new to sales force programming so forgive me if I don't sound like I know what I'm doing....