Salesforce Login Page: Custom login page with Visualforce and Apex for Salesforce Communities

4:39 PM

This article is a simple explanation of the use of the Site.Login() Apex method. The documentation in detail from Salesforce is here http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_sites.htm.

STEP 1:
Enable Communities by going to the below path, Your Name -> Setup ->  App Setup -> Customize -> Communities -> Settings




STEP 2:
Create a new Community as shown below



STEP 3:
Create a Apex Class as shown below


Note: Replace 'null' with the URL to be redirected to after login.

STEP 4:

Create a Visualforce page 'CustomLoginPage' as shown below



STEP 5:
Navigate to Manage Communities from the setup menu, and click the 'Force.com' link as below



STEP 6:

Make the following changes as shown below.

STEP 7:

Modify the Apex Class 'CommunitiesLoginController' as below



STEP 8:

Modify the Visualforce page 'CommunitiesLogin' as below



STEP 9:

Make sure you publish the community. Navigate to the URL and you should see the custom login page as below.








13 comments

  1. Very Sleek explanation...Thanks for the post :)

    ReplyDelete
  2. This login will authenticate with what data?

    ReplyDelete
  3. I did as you wrote, and is not working...

    ReplyDelete
  4. Cool article, Questions tho, are you only redirecting the user to your page when they get to the standard login page? Couldn't this be achieved by just changing settings through the UI?

    ReplyDelete
  5. i tried the above code, but the user is been redirected to same page instead of redirecting to start url or community landing page. Did anyone try this?

    ReplyDelete
    Replies
    1. Yeah I get an infinite loop of login pages too

      Delete
    2. Not Working for me as well.

      Delete
  6. i want to users to redirect to custom URL after login. how to do that?

    ReplyDelete
  7. Thank you so much for the post very clear steps.

    ReplyDelete
  8. Thanks for this code.
    I am facing some difficulties while creating the test class for "customlogincontroller".
    Please share the test class for the same.

    ReplyDelete
  9. Thanks for this code.
    I am facing some difficulties while creating the test class for "customlogincontroller".
    Please share the test class for the same.

    ReplyDelete