Print this page

Apex callout from Salesforce Org to another Salesforce Org

Knowledge Article Number 000232295
Description We can have a Rest Service that can make a Callout to another Salesforce Org .

The following documentation suggests invoking an external Web service from a Salesforce Org.

We can make a Web service Callout from Salesforce Org A to  Org B , if Org B does not make any further Callouts
Resolution Create Web Service in Org B

1. Create Class AccountPlan with Web service Variable and Method  createAccountPlan() of definition webservice static String createAccountPlan() 
2. Generate WSDL for Class AccountPlan . 

Create Rest service in Org A to invoke createAccountPlan() of Org B

3. Use this WSDL to create Class soapSforceComSchemasClassAccplan 
Setup -> Apex Classes -> Generate from WSDL . This create Class soapSforceComSchemasClassAccplan and Class AsyncSoapSforceComSchemasClassAccplan 
4. Create Apex class as follows: 
global with sharing class CallAccountPlan{
    global static String doGet(){
        soapSforceComSchemasClassAccplan.AccountPlan stub = new soapSforceComSchemasClassAccplan.AccountPlan();
        stub.SessionHeader = new soapSforceComSchemasClassAccplan.SessionHeader_element();
        stub.SessionHeader.sessionId = Session Id;
        return stub.createAccountPlan();

5. Add Org B endpoint to Remote Site settings
6. Make a GET call /services/apexrest/createAccountPlan/ from REST explorer in Workbench
7. We see the output string from method createAccountPlan of Org B

Conclusion :
When Rest web service is called from external system, Rest service can make call outs to other Salesforce organizations too.

promote demote