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
raskrenraskren 

Login to another Salesforce instance via s-control

Is it possible to login to a different Salesforce organization (assuming the user/pass is known) via s-control and run queries against the remote data?
 
For example: I administer Salesforce instance A where my s-control runs.  I also want to get data from Salesforce instance B and C which contains data I need to report on.  Can the s-control running in instance A retrieve this data?
 
Thanks.
WhyserWhyser

You may have to get your s-control to open a separate page and have it login to Salesforce in that window as a separate instance.

I've never done it before, but I would use this perhaps as a starting point:

http://www.salesforce.com/us/developer/docs/ajax/Content/sforce_api_ajax_connecting.htm

I think if you re-login to Salesforce into another instance with a new user/password, you probably will lose your current session, unless you plan on going back to it by passing the original user/password credentials to Salesforce again...

raskrenraskren
The s-control would query the remote system and write data back to the master instance.
 
I didn't think about the session management issue...
 
Thanks for the link.  I'm getting the feeling that this may involve too much hackery to be feasible and robust. 
 
If anyone has actually done this let me know!
sfdcfoxsfdcfox
You can do it using the AJAX toolkit in an S-Control, but you will want to "back up" your master Session ID so that you don't lose it. You risk security access violations anyways using JavaScript if the script has to cross domains (so, you might also need to use SOA), so it becomes yet more complex (using the API through a Salesforce proxy). Maybe it might make more sense to use straight SOA and have a remote server access the data. More roundtrip data/bandwidth, but overall would have higher performance, I think. Even better, use Apex Code and have Salesforce connect to it's own API internally. You'd be limited to a handful of data transfers per trip, but you can have it implemented as a webservice and driven by an s-control to control the flow of data, while the Apex Code actually does all of the data transferring and API connections.
raskrenraskren
Can you elaborate a little more on backing up the session ID?  Do you mean storing it in a global JS variable?  Where does one have the opportunity to force Salesforce to use a specific session id?
sfdcfoxsfdcfox

__sfdcSessionId is the injected session ID. You can change the session ID that the AJAX toolkit uses by modifying its internal variable:

Code:
// connect to the other session.
sforce.connection.login('user@company.com','secret1')
// back up this alternate connection point.
__sfdcOtherSessionId = sforce.connection.sessionId;
// restore the original S-Control provided session.
sforce.connection.sessionId = __sfdcSessionId;

You can then switch between the two. Alternatively, you could also create a new connection... I think the syntax would be:

Code:
sforce.connection2 = new sforce.Connection()
sforce.connection2.login('user@company.com','secret')

You could then use sforce.connection to access the original organization, and sforce.connection2 to access the second organization.

raskrenraskren
Cool!  Thanks for the quick response.
 
I was unaware that you could increment the connection method like you did in the example.  That may get me the results I am after.
werewolfwerewolf
Remember that your Salesforce domain can change (sometimes domains split, like when NA3 became NA3 and NA5).  Attempting to use Javascript in this way is going to be very difficult, and you will very likely face cross domain issues, if not now then possibly in the future.
samsonsamson
I've tried to use following code inside S-control:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
    <script type="text/javascript" src="/js/functions.js"></script>
    <script src="/soap/ajax/11.1/connection.js"></script>
    <script type="text/javascript">
 function initPage(){
  try{
   
       sforce.connection2 = new sforce.Connection() sforce.connection2.login('user@company.com','secret')                 
                  
  }
  catch(e)
  {
     alert(e.faultstring);
  }
 
 }
</script>
</head>
<body onload="initPage();">

</body>
</html>
But still get login failure.
 
Need your advise on this , thanks
My requirement is to create a case in other SFDC instance via s-control. Is that possible? Is there any other way to manipulate two instance?
samsonsamson
Suppose there are two SFDC instances named A and B

1.Create a  trigger T inside A using Apex
2. In trigger T, Login into B and create another case inside B

Is that possible? Is there any other good solution to login in to other instance?