+ Start a Discussion
Francesco SciutoFrancesco Sciuto 

Community: create direct login link for internal CRM instance users


I am currently in the process of overriding the native Community login flow of SalesForce with our own custom-made. The custom login flow for Community users (external to our organization) works fine but of course our internal users, if they want to access the community, cannot use the same flow since they need to go to login.salesforce.com (or any othe rinstance URL such as https://na2.salesforce.com), enter their credentials to login to the CRM org and then access the community from there.

Therefore in the login screen for the Community, besides the form to enter the credentials for Communtiy external users, I would like to add a link that redirects our internal users to the CRM login page and still keeping track of the Community URL they were browsing when they were prompted to login.

In order to achieve this, I added the folliwing span element to the SiteLogin component:
<span>Our internal Employee? Login <a href="{! EmployeeLoginURL }">here</a></span>
And in the SiteLoginController (that controls SiteLogin):
global PageReference EmployeeLoginURL {
            String startUrl = System.currentPageReference().getParameters().get('startURL');
            String sfBaseUrl = System.URL.getSalesforceBaseUrl().toExternalForm();
            return new PageReference(sfBaseUrl + '/login?' + startURL);
This code does not work for the following reasons:
  1. In some cases EmployeeLoginURL is the base URL of our Community instead of our CRM instance
  2. In some cases EmployeeLoginURL is treated as a relative path and added to the root path of the communityand generates a page not found error;
  3. The login parameter is (indeed) not a valid one.
In some other SF Community, I noticed that in the login screen they have the same fucntionality I am looking for and the displayed link is in the format:
https://na2.salesforce.com/servlet/networks/session/create?site=0DM400000003deffa&refURL=[some ref url]

That correctly redirects internal users to the SF CRM login screen. I guess this link is machine-generated since it works without modification in both sandbox and production instances. How can I programmaticaly create such URL? Thanks


Maybe a bit late for an answer, but is there any reason why the internal users cannot use the community login ?
It is the same login framework and everything should work (of course you have to make sure that they have access to the pages)
Francesco SciutoFrancesco Sciuto
Thanks Andries, it is never late for an answer. The governance of the company prefers that users login through the org rather than the community. This is also due to the fact that just a small percentage of our internal SF users is also a community user so they do not have access to the community itself. [RES Software] Francesco Sciuto Medior Web Developer Phone: +31 73 6 22 88 00 | Email: F.Sciuto@ressoftware.com
can't you fix it with a Custom login flow ? (https://help.salesforce.com/apex/HTViewHelpDoc?id=security_login_flow.htm&language=en_US)
Francesco SciutoFrancesco Sciuto
Hello Andries, that's what we did. We just miss the code to programmatically create the login link directly to our CRM
Can't you check on an incoming parameter in your login flow and redirect to the community if necessary ? (hard coded/custom setting if needed)