Salesforce/ Apex : using apex connect from salesforce to another other salesforce instance and get session id

Varun   Varun 559 Views
Using Apex If you can to connect from one salesforce to another salesforce instance then following is the code. / how-to-connect-salesforce-to-salesforce

public with sharing class SalesforceApexConnectsToAnotherSalesforce {

    public static String basic(){
   
             Http p = new Http();
             httprequest req= new httprequest();
            req.setMethod('POST');  
            req.setTimeout(60000);
            req.setEndpoint('https://www.salesforce.com/services/Soap/u/22.0');
            req.setHeader('Content-Type', 'text/xml;charset=UTF-8');
            req.setHeader('SOAPAction', '""');
            string body=
                    '<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"><Header/>'+
                    '<Body><login xmlns="urn:partner.soap.sforce.com">'+
                    '<username>' +'*******@*****.com.***dev'+ '</username>'+
                    '<password>' + '********'+ '</password>'+
                    '</login></Body></Envelope>';

            req.setBody(body);
            httpresponse res=new httpresponse();
            res=p.send(req);
            System.debug(res.getBody());

            return res.getBody();
   }
    
}