7

I have created a webservice class in Salesforce Org B (destination).

The purpose of this webservice is to accept values and create a custom object record in Org B.

  1. I generated partner WSDL from Org B and imported into in my Org A (my Source Salesforce Org).

  2. I generated WSDL for my webservice class from Org B and again imported into my Org A (it created two classes)

  3. After adding the remote site settings I wanted to testdrive sending data from Org A to Org B.

This is the code snippet that I tried it in anon apex.

partnerSoapSforceCom.Soap p = new partnerSoapSforceCom.Soap();
String uname = 'UNAME';
String pwd = 'PWD+TOKEN';
partnerSoapSforceCom.LoginResult e = p.login(uname,pwd);
System.debug('The result of the login call is => '+e);
System.debug('ServerURL = '+e.serverURL);//Line 1
System.debug('Session Id = '+e.SessionId);//Line 2



soapSforceComSchemasClassCreateRec.rec rm = new soapSforceComSchemasClassCreateRec.rec();

rm.documentdate = '2016-02-25 00:00:00';
rm.documentid = '1';
rm.Name = 'Test';
soapSforceComSchemasClassCreateRec.rec rd1 = new soapSforceComSchemasClassCreateRec.rec();
rd1.createDocument(rm);

I am able to make a successful handshake and get serverurl and sessionId (Line 1 & Line 2).

After authentication, I am trying to invoke the actual webservice method for creating record and I am getting the following error as below.

enter image description here

I believe it is because I have not set the session Id which I received from Line 2 during the actual invocation.

Can someone tell me how do I actually set the session Id in my request ?

3

Use loginResult.sessionid for sessionid

partnerSoapSforceCom.Soap obj = new partnerSoapSforceCom.Soap();
partnerSoapSforceCom.LoginResult loginResult = obj.login('org@username.com', 'Password');
obj.SessionHeader = new partnerSoapSforceCom.SessionHeader_element();
obj.endpoint_x =loginResult.ServerUrl;
obj.Sessionheader.sessionid = loginResult.sessionid;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.