Is it possible to connect Salesforce to Salesforce in Apex. I want to bring sample records from Full Copy sandbox to config sandbox and I need to do this as I refresh config sandbox.

I think if we can connect to another sandbox via apex we can automate the process of manual data load.

  • 1
    This should work with salesforce to salesforce. I've set up a connection between two sandbox orgs for the same client. Unfortunately salesforce to salesforce can't go from a production org to a salesforce org. Nov 6, 2012 at 3:03

7 Answers 7


This cookbook article, Calling Salesforce Web Services Using Apex shows how to import the Partner API into Apex. You can then call the query and insert operations on that service to communicate with another org. Let me know if this is something you want to explore, I've been having some success with getting the SF SOAP API's working from Apex recently! ;-)

SOAP API Developer's Guide


I agree with PepeFloyd -- If you're just looking to copy data then you could use an app like SFXOrgData (http://www.sfApex.com) to do this. I developed this application specifically for this purpose. It lets you connect to your source org (could be Sandbox or Production) and your target org (again could be Sandbox or Production). I do like the idea of using all native APEX code (while leveraging the SOAP API) to do this, but I think there are a bunch of governor limit's you'll hit if your copying a lot of records.


This sounds like a great use of Salesforce to Salesforce if you don't mind doing all the config to setup the connection. Salesforce to Salesforce only lets you connect sandbox orgs to other sandbox orgs, and production/dev orgs to other production/dev orgs, but there is no limitation for connecting two sandboxes related to the same production org to each other.

Once the config is setup you can use the PartnerNetworkRecordConnection object to automate the sharing.

Let us know how this works out for you!

  • 2
    for those reading this, just to clarify (and this does work) - you can connect a PROD to a DevEdition org - and this will be very useful in running regression tests on any deployed S2S Apex in your PROD org
    – cropredy
    Nov 27, 2014 at 1:59

I reckon Salesforce 2 Salesforce cannot be enabled for two orgs within the same salesforce organisation (I.e. two sandboxes under the same production org) It can only be enabled across two different (partner) orgs, I believe even across two Developer orgs would work.

Besides, a full copy sandbox and a config sandbox will have significant differences in data storage limit.

I've seen a tool like Monarch from Dreamfactory used to seamlessly move data between sandboxes.


The other alternative will be using the Apex DataLoader to move and externalId fields to join up records.

  • 2
    This isn't the case. I've setup s2s from one sandbox to another sandbox that both have the same production org. The only limitation appears to be you can only go from a sandbox to another sandbox, and a production/dev org to another production/dev org. Nov 6, 2012 at 3:05

If all you want is to move data for testing purposes, there is no need for apex. You can do this using Talend (free), Boomi or Informatica Data Loader.

  • Talend is free? Really? Can you share a link with this info? Thanks Nov 22, 2016 at 17:31

The only way to access your data in that way would be to expose it via the SOAP API.

However, you cannot connect to these APIs from APEX.

Since the data doesn't come into your config only sandbox it is kind of an issue for getting data in there. Your also limited on data size to 500mb in config-only orgs.

You might consider:

  • Outside program that has access to both orgs
  • The SFDC data-loader


Perhaps check out: APEX-Metadata API seems promising for your needs. I guess I assumed the external APIs were black-listed from internal domain requests. This apparently is not the case.

  • Thanks for the mention jodran! I believe what he needs is the Partner API, but yes the work I've been doing on the Metadata API and the link to the Cookbook in my answer suggests it is indeed possible, interesting possibilities! :) Oct 25, 2012 at 1:12

I would take a look here for some direction: http://th3silverlining.com/2010/03/28/salesforce-integration-using-wsdls/

You can expose apex classes/methods that will let you query for the data in an SF system via SOAP or Rest - but you will need to handle the authentication (the article above discusses that at length).

The other challenge you have when moving between systems is re-creating the relationships in the target system e.g. associating Contacts with Accounts, since the AccountIds will be different in the target system. So when you create the new contacts, you need to find their parent accounts, and link them to the new AccountId of their parent account. The easiest way in my experience is to create an external Id field called LiveId, populate that field with the Id from the live system, and then use native upsert to correctly associate the child records with their parent in the new system.

You must log in to answer this question.

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