0

I am new for integration.Here i want to create one visual force page with username and password fields in one developer edition.So that if i give login id and password of another developer edition,we can login into that developer account.Can you please help me to understand this problem.

0

Remote site settings: https://login.salesforce.com/(login url of organization)

Visual force page:

// Salesforce to Salesforce

<body>
    <!-- Begin Page Content -->
    <div id="container">
        <form>
            <label for="username">Username:</label>
            <apex:inputtext value="{!username}"/>
            <label for="password">Password:</label>
            <apex:inputsecret value="{!password}"/>
                <div id="lower">               
                    <apex:commandbutton value="Login" action="{!loginn}"/>
                </div><!--/ lower-->
        </form>
    </div><!--/ container-->
    <!-- End Page Content -->
</body>

controller: public with sharing class s2s{

public String username {get; set;}
public string password {get; set;}
private static final String NS_SOAP = 'http://schemas.xmlsoap.org/soap/envelope/';
private static final String NS_SF = 'urn:partner.soap.sforce.com';

public pagereference loginn()
{
   HttpRequest req = new HttpRequest();
   req.setMethod('POST');   
   //  req.setTimeout(60000);
   req.setEndpoint('https://login.salesforce.com/services/Soap/u/29.0');

   req.setHeader('Content-Type', 'text/xml;charset=UTF-8');

   req.setHeader('SOAPAction', 'create');

   req.setBody('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"><Header/><Body><login xmlns="urn:partner.soap.sforce.com"><username>' +username+ '</username><password>' + password + '</password></login></Body></Envelope>');

   HttpResponse res =  new Http().send(req);
      system.debug(res.getBody());
    Dom.Document responseDocument = res.getBodyDocument();
    system.debug('response:'+responseDocument);
    Dom.Xmlnode rootElm = responseDocument.getRootElement(); // soapenv:Envelope
    Dom.Xmlnode bodyElm = rootElm.getChildElement('Body', NS_SOAP); // soapenv:Body 
    Dom.Xmlnode loginResponseElm = bodyElm.getChildElement('loginResponse', NS_SF); // loginResponse
    Dom.Xmlnode resultElm = loginResponseElm.getChildElement('result', NS_SF); // result
    Dom.Xmlnode sessionIdElm = resultElm.getChildElement('sessionId', NS_SF); // sessionId

 final String SERVER_URL = resultElm.getChildElement('serverUrl', 'urn:partner.soap.sforce.com') .getText().split('/services')[0];

 final String SESSION_ID = resultElm.getChildElement('sessionId', 'urn:partner.soap.sforce.com') .getText();
 system.debug('sessionid:'+SESSION_ID);

//dom.document rese = ET_EmailAdministration.sendemail(SERVER_URL,SESSION_ID,username,password); pagereference p = new pagereference(SERVER_URL+'/secur/frontdoor.jsp?sid='+SESSION_ID); p.setredirect(TRUE); return p; } public class LoginException extends Exception {} }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy