0

I am trying to connect two Salesforce Org and create a case in Client SFDC org via SOAP API by using WSDL files at both end.

I have used following code at server for WSDL file generation(and used Partner WSDL API):

global class CaseServer{

    webservice static string CreateCase (String Status, String Origin){
        Case Newcase= new Case();
        Newcase.Status = Status;
        Newcase.Origin = Origin;

        try {
        insert Newcase;
        return 'Success';
        } catch (DmlException e) {
        return e.getMessage();
         }
    }
}

I executed below anonymous block in client sfdc:

string username='MyUsername';

string password = 'MyPassword';

partnerSoapSforceCom.LoginResult sessionInfoObj = new partnerSoapSforceCom.LoginResult();

partnerSoapSforceCom.soap soapObj = new partnerSoapSforceCom.soap();

soapObj.login(username,password);

soapCaseserver.SessionHeader_element sessionElemnetObject = new soapCaseserver.SessionHeader_element();

sessionElemnetObject.sessionId = sessionInfoObj.sessionId;

soapCaseserver.CaseServer wsobj = new soapCaseserver.CaseServer();

wsobj.SessionHeader = sessionElemnetObject;

wsobj.CreateCase('New','Phone');

Error: Error: System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session faultcode=sf:INVALID_SESSION_ID faultactor=

Basic Checks that i performed:

Ip range is from 0.0.0.0 to 255.255.255.255 in Server

    Not appended security token, as already allowed all ip range, as per
    above point.

    Above code is performed in client anonymous window.

    Added both end point url in client Remote site settings.

    Tried to create a case with above two parameters. Case was
    successfully created in Server.

    When i execute above code, there is successful login in Server. It
    is visible in login history.

Can anyone please suggest what i am missing out here??

0

You didn't actually get the login result from the server, you just constructed one, and used that one instead. This variable has no data in it, so the sessionId is null, hence invalid.

partnerSoapSforceCom.LoginResult sessionInfoObj = new partnerSoapSforceCom.LoginResult();

partnerSoapSforceCom.soap soapObj = new partnerSoapSforceCom.soap();

soapObj.login(username,password);

Instead, you need to get the login result from the login call:

partnerSoapSforceCom.soap soapObj = new partnerSoapSforceCom.soap();
partnerSoapSforceCom.LoginResult sessionInfoObj = soapObj.login(username,password);

Note that you also need to set/reset (whichever term you prefer) the endpoint to the serverUrl returned in this login call.

| improve this answer | |
  • Thanks for resolution . But I didn't reset the endpoint to the server URL. It's working fine!! – KKumar Apr 28 at 3:22

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.