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
satheesh8.k1.3890099515516848E12satheesh8.k1.3890099515516848E12 

Salesforce to salesforce Integration Process

Hi All,
Please help me how to do salesforce to salesforce integation using Rest API's.

I have a link: https://resources.docs.salesforce.com/sfdc/pdf/api_rest.pdf

i follow this pdf , but  api's are not working , may be my process is wrong or anything i missed . i don't know where i did mistake.

Please give me clear steps.

Thanks
Satheesh
Best Answer chosen by satheesh8.k1.3890099515516848E12
Ajay K DubediAjay K Dubedi

Hi Satheesh,
1 . Create a connected app in the target org.

2. Give all the permissions and call back url in the format https://www.xyz.comm

3. Create remote site in you org and add the url of the target org.

and use the code below it is working for me.
public String instanceUrl;
 public final string endPointUrl='https://login.salesforce.com/services/oauth2/token';
 public final String clientId ='connected app client id';
 public final string clientSecret='connected app secret key';
 public final String userName = 'target user name';
 public final String password = 'target password';
    
    public WebServiceRestotherOrg(){
        HttpRequest req = new HttpRequest();
        req.setMethod('POST');
        req.setEndpoint(endPointUrl);
        req.setBody('grant_type=password' + 
                    '&client_id='+ clientId + 
                    '&client_secret='+ clientSecret +
                    '&username=' + EncodingUtil.urlEncode(userName, 'UTF-8') + 
                    '&password=' + EncodingUtil.urlEncode(password, 'UTF-8'));
        Http h = new Http();
        Httpresponse res = h.send(req);
        string body = res.getBody();  
        
        system.debug('***** Body -- '+ body);
        
        wObj = (wrapperForHttp)Json.deserialize(body,wrapperForHttp.class);
        accessToken = wObj.access_token;
        instanceUrl = wObj.instance_url;
        system.debug('***** accessToken -- '+ accessToken + ' **** instanceUrl -- '+ instanceUrl);
              getMethod();
    }
    
    public void getMethod(){
        try{
        string queryUrl = '/services/apexrest/hello1?Accid=xyz&emailid=abc@gmail.com&companyName=test';
        HttpRequest req = new HttpRequest();
        req.setMethod('POST');
        req.setEndpoint(instanceUrl + queryUrl);
        system.debug('*** req**' +req);
        req.setHeader('Content-Length', '0');
        req.setHeader('Authorization', 'OAuth '+ accessToken);
        Http http = new Http();
        HTTPResponse res = http.send(req);
        System.debug('BODY: -- '+res.getBody());
        System.debug('-------Inserted Successfully-----');
    }

    catch(Exception e){
        system.debug('------Error Message------' +e.getMessage());
    }
        }
    
       }
    
    public class wrapperForHttp{
        String Id;
        String instance_url;
        String issued_at;
        String token_type;
        String signature;
        String access_token;
    }
}
Create this mapping class in the target org and use the below parameters in url same as given below i.e AccId,EmailId & companyName
so this code will insert an account in the other org.
@RestResource(urlMapping='/hello/*')
global class RestApigee {
  @HttpPost
  global static Contact helloWorld1(){
    RestRequest req = RestContext.request;
    string test = req.params.get('AccId');
    string test1 = req.params.get('emailId');
    string company = req.params.get('companyName');
    
    Contact con = new Contact();
    con.LastName = company;
    con.firstName = test;
    con.Email = test1;
    insert con;
    return con;
  }
}

 

All Answers

NagaNaga (Salesforce Developers) 
Hi Satheesh,

Salesforce to Salesforce enables business collaboration both within and across Salesforce organizations. This allows you to share certain records with your business partners that use Salesforce and get real-time updates on the shared data. For example, you can share lead and opportunity data with business partners and manage your entire pipeline and programs within Salesforce.

Salesforce to Salesforce allows you and your business partners to collaborate more easily and effectively. With Salesforce to Salesforce, you can share records with one or more connections, and each connection can accept records you share with them - even if other connections have accepted the same record.Salesforce to Salesforce allows your business partners to:Access all their programs from one place
Easily integrate your data with the data they manage in Salesforce
Integrate their business processes with updates received from youSalesforce to Salesforce allows you to:Have 100% visibility into your partner activity
Manage your entire pipeline, both internal sales and channel sales, in one place
Rapidly and easily share data across multitiered partnerships
Integrate your business processes with updates received from your partners using workflow and assignment rules

If you want to connect to partners but aren't sure if they use Salesforce, you can use connection finder to find out.

If you receive an invitation to connect with a business partner using Salesforce to Salesforce, see Accepting or Rejecting an Invitation to Join Salesforce to Salesforce.

To invite other companies to connect with you using Salesforce to Salesforce, see Inviting Business Partners to Connect using Salesforce to Salesforce.

Please see the link below

https://help.salesforce.com/apex/HTViewHelpDoc?id=business_network_intro.htm

Best Regards
Naga Kiran
Ajay K DubediAjay K Dubedi

Hi Satheesh,
1 . Create a connected app in the target org.

2. Give all the permissions and call back url in the format https://www.xyz.comm

3. Create remote site in you org and add the url of the target org.

and use the code below it is working for me.
public String instanceUrl;
 public final string endPointUrl='https://login.salesforce.com/services/oauth2/token';
 public final String clientId ='connected app client id';
 public final string clientSecret='connected app secret key';
 public final String userName = 'target user name';
 public final String password = 'target password';
    
    public WebServiceRestotherOrg(){
        HttpRequest req = new HttpRequest();
        req.setMethod('POST');
        req.setEndpoint(endPointUrl);
        req.setBody('grant_type=password' + 
                    '&client_id='+ clientId + 
                    '&client_secret='+ clientSecret +
                    '&username=' + EncodingUtil.urlEncode(userName, 'UTF-8') + 
                    '&password=' + EncodingUtil.urlEncode(password, 'UTF-8'));
        Http h = new Http();
        Httpresponse res = h.send(req);
        string body = res.getBody();  
        
        system.debug('***** Body -- '+ body);
        
        wObj = (wrapperForHttp)Json.deserialize(body,wrapperForHttp.class);
        accessToken = wObj.access_token;
        instanceUrl = wObj.instance_url;
        system.debug('***** accessToken -- '+ accessToken + ' **** instanceUrl -- '+ instanceUrl);
              getMethod();
    }
    
    public void getMethod(){
        try{
        string queryUrl = '/services/apexrest/hello1?Accid=xyz&emailid=abc@gmail.com&companyName=test';
        HttpRequest req = new HttpRequest();
        req.setMethod('POST');
        req.setEndpoint(instanceUrl + queryUrl);
        system.debug('*** req**' +req);
        req.setHeader('Content-Length', '0');
        req.setHeader('Authorization', 'OAuth '+ accessToken);
        Http http = new Http();
        HTTPResponse res = http.send(req);
        System.debug('BODY: -- '+res.getBody());
        System.debug('-------Inserted Successfully-----');
    }

    catch(Exception e){
        system.debug('------Error Message------' +e.getMessage());
    }
        }
    
       }
    
    public class wrapperForHttp{
        String Id;
        String instance_url;
        String issued_at;
        String token_type;
        String signature;
        String access_token;
    }
}
Create this mapping class in the target org and use the below parameters in url same as given below i.e AccId,EmailId & companyName
so this code will insert an account in the other org.
@RestResource(urlMapping='/hello/*')
global class RestApigee {
  @HttpPost
  global static Contact helloWorld1(){
    RestRequest req = RestContext.request;
    string test = req.params.get('AccId');
    string test1 = req.params.get('emailId');
    string company = req.params.get('companyName');
    
    Contact con = new Contact();
    con.LastName = company;
    con.firstName = test;
    con.Email = test1;
    insert con;
    return con;
  }
}

 
This was selected as the best answer