1

I have two Orgs, the service ORG and the client Org. I want to feed data from service ORG into client org.

I read from these two places:

1.https://developer.salesforce.com/page/Apex_Web_Services_and_Callouts

2.How do invoke an apex method of one org, from another org?

Here's my steps:

In the Service Org:

  1. Create the web service class

  2. Download the WSDL file auto generated from this web service class

In the Client Org:

  1. Import the WSDL file to generate apex classes. (One Async and one Sync);

  2. Write apex to call the web service using generated apex method.

In step 4, I was not able to set a correct session ID for the service client. Did I miss any steps?

Code of Step 4:

ARTaskWebService.AR_getActivitiesWebservice client=new ARTaskWebService.AR_getActivitiesWebservice();
client.SessionHeader = new ARTaskWebService.SessionHeader_element();
client.SessionHeader.sessionId=???? 

List<ARTaskWebService.ARActivity> activities = client.getActivities('Client Name');
System.debug(activities.size());

I tried to use the partner wsdl of Service Org to generate the login method in Client Org and get the session ID by calling the login method. But I got an error "WebService returned a SOAP Fault: INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session. Session not found, missing session key: "

1 Answer 1

2

You will need to set the endpoint for the client based on the LoginResult serverUrl.

The login call will go to login.salesforce.com. When it comes back the serverUrl will be something like https://na5.salesforce.com/services/Soap/u/34.0.

partnerSoapSforceCom.Soap partner = new partnerSoapSforceCom.Soap();
partnerSoapSforceCom.LoginResult lr = partner.login('[email protected]', 'SomePassword' + 'SomeSecurityToken');    

ARTaskWebService.AR_getActivitiesWebservice client = new ARTaskWebService.AR_getActivitiesWebservice();
client.SessionHeader = new ARTaskWebService.SessionHeader_element();
client.SessionHeader.sessionId = lr.sessionId;

// You may need to adjust this if using a custom Apex Soap service.
client.endpoint__x = lr.serverUrl;

Since your Apex class Soap class probably has an endpoint like https://na8.salesforce.com/services/Soap/class/AR_getActivitiesWebservice you may need to adjust this using the domain in the LoginResult serverUrl.

E.g. replace the na8 pod identifier in your current endpoint with na5 if that is what the serverUrl comes back with.

2
  • Daniel, this works! Thank you so much! I got an 'na28' from the login result. Why are there so many end points involved?
    – sfdcnoob
    Commented Aug 17, 2015 at 22:14
  • Those na28/na5 sub domains are Salesforce pods/instances. They are independent sets of servers. Each pod hosts a certain number of independent organizations. Commented Aug 17, 2015 at 22:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .