1

If the SSO is set up, can we use frontdoor.jsp without using Username password? I would like to access the second salesforce org from first salesforce org. SSO has been set up already. Canvas application does not serve the purpose because it will not give access to standard record detail page.Existing code below, uses username, password and we would like to avoid using that.

private static String login(String un,String pw,String 
                                         domain){
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://' + domain + 
              '.salesforce.com/services/Soap/u/30.0');
        request.setMethod('POST');
        request.setHeader('Content-Type', 'text/xml;charset=UTF-8');
        request.setHeader('SOAPAction', '""');
        request.setBody('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"><Header/><Body><login xmlns="urn:partner.soap.sforce.com"><username>' + un + '</username><password>' + pw + '</password></login></Body></Envelope>');
        Http h = new Http();
        HttpResponse res = h.send(request);        
        return res.getBody();
    }



    String loginRes = createLoginRequest(username,password,domain);
        if(!String.isBlank(loginRes) && !loginRes.containsIgnoreCase('INVALID_LOGIN')){
            Dom.Document loginDoc = new Dom.Document();
            loginDoc.load(loginRes);
            Dom.XmlNode resultElmt = loginDoc.getRootElement()
              .getChildElement('Body','http://schemas.xmlsoap.org/soap/envelope/')
              .getChildElement('loginResponse','urn:partner.soap.sforce.com')
              .getChildElement('result','urn:partner.soap.sforce.com');

            /*Get the session Id and Server url*/
            String serverurl = resultElmt.getChildElement('serverUrl','urn:partner.soap.sforce.com').getText().split('/services')[0];
            String sessionId = resultElmt.getChildElement('sessionId','urn:partner.soap.sforce.com').getText();

            /*Use frontdoor.jsp to login to salesforce*/
            loginReference =  new Pagereference(serverurl+'/secur/frontdoor.jsp?sid='+sessionId+'&retURL=https://SALESFORCEURL/apex/myVFpage?id='+abcId);
            //loginReference =  new Pagereference(serverurl+'/secur/frontdoor.jsp?sid='+sessionId+'&retURL=https://NA999.salesforce.com/'+abcId);

        }
        else{
            Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Username or Password Incorrect'));
        }
   }
1

frontdoor.jsp works with a session ID. To obtain the session ID, you have to provide a credential when authenticating to Salesforce. Often this credential is a username/password pair as your code sample shows.

If SSO is set up between two orgs, you don't need frontdoor.jsp.

  • Thank you identigral! If SSO is set up, what can I use to achieve this functionality? – Suraj May 5 '19 at 3:31
  • Can I just use URL redirects to the other org? – Suraj May 5 '19 at 3:46
  • @Suraj Yes, try that – identigral May 5 '19 at 16:45
  • Thanks a lot! I will try it and let you know!! – Suraj May 5 '19 at 16:47
  • I tried that. Unfortunately it is taking the user to login screen. Code below public Pagereference login(){ Pagereference loginReference; currentRecordId = ApexPages.CurrentPage().getparameters().get('id'); getId = [query]; loginRef = new Pagereference('INSTANCE.visual.force.com/apex/VFPAGE?id='+getId); return loginRef; } } – Suraj May 5 '19 at 21:11

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.