You need to sign in to do that
Don't have an account?
Trying to make API call to another Salesforce Org
I started with this cookbook, which was great.
http://developer.force.com/cookbook/recipe/calling-salesforce-web-services-using-apex
I just want to call a custom WebService instead of a Describe call.
webservice static string processInboundMessage(string msgType, string xmlString)
Here is my code...
partnerSoapSforceCom.Soap sp = new partnerSoapSforceCom.Soap();
String username = 'myUserName';
String password = 'myPasswordMySecurityToken';
partnerSoapSforceCom.LoginResult loginResult = sp.login(username, password);
system.debug('Session ID: ' + loginResult);
string sessionHeaderSection = '';
sessionHeaderSection = '<soapenv:Header><hel:SessionHeader><hel:sessionId xsi:type="xsd:string">' + loginResult.SessionID + '</hel:sessionId></hel:SessionHeader></soapenv:Header>';
Http h = new http();
HttpRequest req = new HttpRequest();
req.setEndpoint('https://cs8-api.salesforce.com/services/Soap/class/WbsrRegInterface');
//req.setEndpoint('https://cs8-api.salesforce.com/services/Soap/class/WbsrRegInterface?wsdl');
req.setMethod('POST');
req.setHeader('Content-Type', 'text/xml;charset=utf-8');
req.setHeader('SOAPAction', 'http://soap.sforce.com/schemas/class/WbsrRegInterface');
string msgType = 'REG';
string xmlStringToSend = 'MYXML';
string b ='<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:hel="http://soap.sforce.com/schemas/class/WbsrRegInterface">'+sessionHeaderSection+'<soapenv:Body><hel:processInboundMessage><hel:msgType>'+msgType+'</hel:msgType><hel:xmlString>'+xmlStringToSend+'</hel:xmlString></hel:processInboundMessage></soapenv:Body></soapenv:Envelope>';
req.setHeader('Content-Length',String.valueOf(b.length()));
req.setbody(b);
HttpResponse res = h.send(req);
system.debug('RESPONSE: ' + res.getBody() );
My login works and I know I am hitting my destination org because I can see it in the login history.
My error is:
<faultstring>The element type "soapenv:Body" must be terminated by the matching end-tag "</soapenv:Body>".</faultstring>
The XML I am sending looks like this:
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:hel="http://soap.sforce.com/schemas/class/WbsrRegInterface">
<soapenv:Header>
<hel:SessionHeader>
<hel:sessionId xsi:type="xsd:string">
00DL00000004YnR!ARIAQGHH9372teOXPI4.ZyepVnvUCXvndwhToI370HHrskPbloo80NCHNXjFHmrFSs4FAUSPNVVGRqLOQy.6IN_lBR8RZuAg
</hel:sessionId>
</hel:SessionHeader>
</soapenv:Header>
<soapenv:Body>
<hel:processInboundMessage>
<hel:msgType>REG</hel:msgType>
<hel:xmlString>fred</hel:xmlString>
</hel:processInboundMessage>
</soapenv:Body>
</soapenv:Envelope>
Any ideas?
Hi Terry,
Please have a look oon this article, if you can get something usefull from here:
http://shivasoft.in/blog/salesforce/getting-record-from-one-salesforce-organization-to-other/
All Answers
I have found that importing my WSDL does work, but I would still like to know how to generate the full XML.
//Call the partner API to get the Session ID
partnerSoapSforceCom.Soap sp = new partnerSoapSforceCom.Soap();
String username = 'myUserName';
String password = 'myPasswordmySecurityToken';
partnerSoapSforceCom.LoginResult loginResult = sp.login(username, password);
//Now that I have the session id I can call my Salesforce Web Service
soapSforceComSchemasClassWbsrregint.WbsrRegInterface wbs = new soapSforceComSchemasClassWbsrregint.WbsrRegInterface();
String retVal = '';
//I do not have to set the endpoint_x as it is already specified in the WSDL, but I may want to change it to point to other Orgs later
wbs.endpoint_x = 'https://cs8-api.salesforce.com/services/Soap/class/WbsrRegInterface';
wbs.SessionHeader = new soapSforceComSchemasClassWbsrregint.SessionHeader_element();
wbs.SessionHeader.sessionID = loginResult.SessionID;
retVal = wbs.processInboundMessage('REGX', 'TESTXML');
If I could even debug out what the actual XML is from the WebServiceCallout.invoke call is, then maybe I could figure out how to generate the XML myself.
This post taught me how to do the above work-around...
http://boards.developerforce.com/t5/Apex-Code-Development/Apex-Callouts-to-Apex-Web-Service-Automated-S2S-Possible/m-p/126591/highlight/true#M15541
Hi Terry,
Please have a look oon this article, if you can get something usefull from here:
http://shivasoft.in/blog/salesforce/getting-record-from-one-salesforce-organization-to-other/