Hi I'm attempting to use a custom visualforce page to login external communities users (customers). I have read the implementation guide this guide and followed all the instructions. But when I enter the credentials for a test user on my VF login page, it takes me to the landing page instead of the homepage. I have also looked at this doc for customizing portal logins but I'm not sure what I'm missing. Below are my customLoginController,CommunitiesLandingController, SiteController, CommunitiesLogin and CommunitiesLanding.

global with sharing class CommunitiesLoginController {

    global CommunitiesLoginController () {}

    // Code we will invoke on page load.
    /**global PageReference forwardToAuthPage() {
        String startUrl = System.currentPageReference().getParameters().get('startURL');
        String displayType = System.currentPageReference().getParameters().get('display');
        return Network.forwardToAuthPage(startUrl, displayType);

    global PageReference forwardToCustomAuthPage() {
        String startUrl = System.currentPageReference().getParameters().get('startURL');
        return new PageReference(Site.getPrefix() + '/MYCustomerPortalLogin?startURL=' +
        EncodingUtil.urlEncode(startURL, 'UTF-8'));

public with sharing class CommunitiesLandingController {

    // Code we will invoke on page load.
    public PageReference forwardToStartPage() {
        return Network.communitiesLanding();

    public PageReference forwardToCustomAuthPage() {
        String startUrl = System.currentPageReference().getParameters().get('startURL');
        return new PageReference(Site.getPrefix() + '/MYCustomerPortalLogin?startURL=' +
        EncodingUtil.urlEncode(startURL, 'UTF-8'));

    public CommunitiesLandingController() {}

global with sharing class SiteLoginController {
    global String username {get; set;}
    global String password {get; set;}

    global PageReference login() {
        String startUrl = System.currentPageReference().getParameters().get('startURL');
        return Site.login(username, password, startUrl);

     global SiteLoginController () {}

<apex:page id="loginPage" controller="CommunitiesLoginController" action="      {!forwardToCustomAuthPage}" title="{!$Label.site.site_login}"> 

<apex:page id="communitiesLandingPage" controller="CommunitiesLandingController" action="{!forwardToCustomAuthPage}" title="{!$Label.site.site_login}">

<apex:page showHeader="false" controller="SiteLoginController"
standardStylesheets="false" sidebar="false">

    <title>Customized Customer Login</title>

    <script type='text/javascript'>
    function noenter(ev)  {
        if (window.event && window.event.keyCode == 13 || ev.which == 13) {
            return false;
         } else {
              return true;
    <style type="text/css">
         fieldset.login {
            background: none repeat scroll 0 0 white;
            border: 1px solid #AAAAAA;
            border-radius: 5px 5px 5px 5px;
            font-family: "Century Gothic","Lucida Grande",Arial,sans-serif;
            margin: 0 0 25px;
            padding: 10px;

        fieldset.login label {
            clear: both;
            color: #333333;
            display: block;
            font-size: 12px;
            font-weight: bold;
            padding-top: 10px;

        fieldset.login input.text {
            border: 1px solid #AAAAAA;
            color: #5E5E5E;
            float: left;
            padding: 5px;
            width: 320px;

        .clear {
            clear: both;

        .content {
            margin: 0 auto;
            width: 419px;
    <div class="content">
        <div class="login">
            <apex:form id="loginForm" forceSSL="true">
                <apex:actionFunction name="javascriptLogin" action="{!login}" />
                <fieldset class="login">
                    <b>Customer Login</b>
                    <apex:pageMessages id="error" />

                    <apex:outputLabel styleClass="label"
                        value="{!$Label.site.username}" for="username" />
                    <apex:inputText styleClass="text" id="username"
                        value="{!username}" />
                    <apex:outputLabel styleClass="label"
                        value="{!$Label.site.password}" for="password" />
                    <apex:inputSecret styleClass="text" id="password"
                        value="{!password}" onkeypress="return noenter(event);" />

                    <div class="clear"></div>
                    <span class="form-link"> </span>
                    <div class="clear"></div>
                        <apex:commandButton value="Login" styleClass="button"
                            action="{!login}" id="submitbutton" />



Salesforce support engineer got back to me and he identified the problem as an error in the Communities Implementation Guide. Here are the changes he suggested for steps # 7 and 15 in the implementation guide(I have implemented these changes and it works):

Step 7:

Add the following code:

 public PageReference forwardTocustomStartPage() {
     return new PageReference('/LANDING_VF_PAGE_NAME_WITH PARAMETERS_IF_ANY');

Step 15. In the first line of code, add the following:



  • How are redirecting to your custom communities login page from the welcome email to community member – sfdc Oct 15 '13 at 20:24
  • @sf.dev i didn't quite understand your question. Could you be a bit clearer? Thanks. – sw6 - KTBFFH Oct 16 '13 at 16:02
  • When you create a new community user ..an email will be sent to the user with link to community login page..how are u redirecting to the community login page – sfdc Oct 16 '13 at 16:10
  • 1
    ok. I understand what you mean now. You will need to change the {!community_url} to whatever the URL to your login page is in the New Member Welcome Email template. Setup => Personal Setup => Email => My Templates => Communities: New Member Welcome Email. I Hope that answers your question. – sw6 - KTBFFH Oct 16 '13 at 17:08
  • How are you authenticating users on custom login page? and How are you redirecting to custom login page when users click on Logout – sfdc Nov 7 '13 at 15:55

After applying custom community log in page you should change the Active site homepage to your custom visualforce page. By going to

Customize | Manage Communities > Force.com Site > Edit and change Active Site homepage to your custom vf page.

You should provide access to communities to that page also.

  • hi responsive - i did like you suggested and made my custom vf page my active site homepage but that brought up another issue - when I enter the login credentials I keep being re-directed to my custom vf page. Did you by any chance see anything wrong with my code or could you share a sample login apex code that works for Salesforce communities. Thanks – sw6 - KTBFFH Sep 23 '13 at 15:08

In general, a landing page should direct you to your start URL or landing page automatically if the user has an active session or to the login page if the user is not authenticated yet. Your forwardToCustomAuthPage() method is always returning your login page, which is the behavior you're observing. Instead of always returning the login page, try adding some logic into the forwardToCustomAuthPage() method.

public PageReference forwardToCustomAuthPage() { 
     if (UserInfo.getUserType()=='Guest') {
        return Page.MYCustomerPortalLogin; //and whatever startURL you want 
     } else { 
        return YOUR_START_URL //if one was provided, otherwise some default home/landing page
  • I will give your suggestions a go as well to see how that works out. Will be back with feedback. Thanks. – sw6 - KTBFFH Sep 24 '13 at 2:16

After much sanity check from my colleague, we concluded that it was either an error unique to us or the documentation was misleading us since we have evrything set up as suggested in the communities implementation guide. My colleague came up with the bright idea of re-directing to our communities apex homepage from whatever page that salesforce directs us to when we log in using the custom vf page. He added an if statement to check the url which the login defaults to and then setting the StartUrl to our communities custom homepage. That's good enough. However we are logging a case with Salesforce support to find out why the directions in the implementation guide did not work in our case and I'll be updating this post once I get a meaningful feedback from them. Hopefully that would help others in the future.

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.