I have already connected both orgs using REST API web-server flow.

What should I use, Tooling API? APEX REST? How do I connect them?

2 Answers 2


An easy and robust way to achieve this would be using a web service:

Service org:

  1. make your class global and give your method(s) the webservice keyword:

    global class AnkuliService {
        webservice static List<String> someMethod(String someParam) {
            return new List<String>{'herp', 'derp', 'doop'};
  2. in to Setup > Apex Classes, locate it and generate a WSDL,

    ankuli wsdl

Client org:

  1. from Setup > Apex Classes, choose Generate from WSDL (give it a friendly name like Ankuli)

    enter image description here

  2. add a Remote Site Setting for your service org (eg https://na1.salesforce.com/)

  3. write Apex to call the service from the remote org:

    //prepare the client
    Ankuli.AnkuliService client = new Ankuli.AnkuliService();
    client.SessionHeader = new Ankuli.SessionHeader_element();
    client.SessionHeader.sessionId = valid_session_id;
    //invoke the method
    List<String> strings = client.someMethod('derp');
    System.debug(strings); //(herp, derp, doop)
  • Isn't parsing the WSDL on the other end tricky in SF? Wouldn't REST be more appropriate since he's already connected both orgs? Commented Jan 29, 2014 at 13:07
  • no, ignore me - i'm clearly thinking of something else Commented Jan 29, 2014 at 13:18
  • 1
    WSDL2APEX rocks so long as there's no SOAP1.2 or complex typess involved @PhilHawthorn Commented Jan 29, 2014 at 13:20
  • i couldn't get your 3rd point, i executed this apex code of 3rd point in client org using developer console but this didn't work. even it seems like SOAP..have u solution for this using REST , it would be great , if you have.
    – Ankuli
    Commented Jan 29, 2014 at 13:51
  • @Ankuli what's the signature and return type of your method? Can you elaborate on the error? Commented Jan 29, 2014 at 14:15

If you are exposing a REST resource you can use HTTP classes to make a callout from the other org. You have to add a connected app/ remote site setting.

  • can you help me to write a code for exposing a class using REST resource.
    – Ankuli
    Commented Jan 29, 2014 at 14:02
  • 1
    You have to write a global class with @RestResource annotation. You have to provide a urlmapping parameter for the annotation. This URLmapping is used to invoke the static get,post.... Methods from an external system. You have to use oAuth for this.
    – zuke
    Commented Jan 29, 2014 at 14:19
  • i got my problm, my org was connecting to itself, so it was not unable to find that mapped url, which is in another org. so can you tell me how to do 1st step of authorization for getting authorization code in web-server flow between two sf org .?
    – Ankuli
    Commented Feb 4, 2014 at 6:46

You must log in to answer this question.

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