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
SFDC 2017SFDC 2017 

How to Integrate from one salesforce Org to another Salesforce Org using APEX REST API?i.e how to call through URL ?????????????

Salesforce to Salesforce is a feature that lets you configure two environments (orgs) so that they share data records in real time. It is natively supported. 
Check these for more details,
SFDC 2017SFDC 2017
Thankyou @ akram.

My scenario i want to Integrate from one salesforce org to another salesforce Org using APEX REST API.Currently i referred Jitendrazaa Website for fetching data from one org to another using Remote site settings.But i want to call a method in Target ORG that i have written in my source ORG .How can we achieve this???

Any help will be Really Appreciable.Currently I am Using Basic Apex REST Example as follows:

global with sharing class MyRestResource
global static void doDelete()
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
Account account = [SELECT Id FROM Account WHERE Id = :accountId]; delete account;
global static Account doGet()
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
Account result = [SELECT Id, Name, Phone, Website FROM Account WHERE Id = :accountId];
return result;
global static String doPost(String name, String phone, String website)
Account account = new Account();
account.Name = name; = phone; = website;
insert account;
return account.Id;

How to call this in my Dev Org .I have added the URL OF the Source Org in Remote site settings in DEV Org.
But i am not clear how to call like or something like that .

Since I am new to Integration i am not able to do this.Everywhere they mention curl to check but i want to call the Url which i mapped first in the to call this class method through URL in another org. 

can you guide me to get this done ...

Thanks in advance.
SFDC 2017SFDC 2017
I want this done using REST Api.

Thanks in advance....
Salesforce REST API call into platform requiresOAuth 2.0 authentication.
Below url may help you.
Suraj Tripathi 47Suraj Tripathi 47

1)Go to setup in source org->search->App Manager in quick find->Create Connected App.
2)After this  Develop  Apex RestService in the Same Source Org.
Sample code: In this, I am Fetching Account.
global with sharing class MyRestResource {
    global static Account getRecord() {
        RestRequest req=RestContext.request;
        RestResponse res=RestContext.response;
        String urlId=req.requestURI.subString(req.requestURI.lastIndexOf('/')+1);
        Account accountList=[SELECT Id,Name,Phone,Description,Rating FROM Account WHERE Id =:urlId];
        return accountList;
3)Now, We use the above Apex Rest Service in Target Salesforce Org.
Sample code-:In this I am fetching accounts from one org to another.
public class MyFirstRestApi {
    public static void getAccount(){
        HttpRequest req=new HttpRequest();
        String CLIENT_ID = '3MVG9fe4g9fhX0E7c0s6z5_ojYYqdlgULEYYd4azO4hjX2hlWYb4jaNMUX.fYNikWLjDEmG3YMURayF.ySmbh';
        String CLIENT_SECRET = '379438EC996D2345F3632774AA40F7DF0A63D004C02C9781CDE6DA6F1623D92A';
        String USERNAME = '';
        String PASSWORD = 'Nainsi420@ujaA865VERblPRkzjb1TOeetE';
        req.setBody('grant_type=password' + '&client_id='+CLIENT_ID + 
                    '&client_secret='+CLIENT_SECRET + '&username='+USERNAME + '&password='+PASSWORD);
        Http http=new Http();
        HttpResponse res=new HttpResponse();
        System.debug('response-->: '+res.getBody());
        Oauth objAuthInfo=(Oauth)JSON.deserialize(res.getBody(), Oauth.class);
            HttpRequest req1=new HttpRequest();
            req1.setHeader('Authorization','Bearer '+objAuthInfo.access_token);
            Http http1=new Http();
            HttpResponse res1=new HttpResponse();
            System.debug('Status -->: '+res1.getStatusCode());
            System.debug('Account Info-->: '+res1.getBody());
    public class Oauth{
        public String access_token{get;set;}
        public String instance_url{get;set;}
        public String id{get;set;}
        public String token_type{get;set;} 
        public String issued_at{get;set;}
        public String signature{get;set;}

You can take references from this link.

If you find your Solution then mark this as the best answer. 

Thank you!

Suraj Tripathi