Saturday 17 November 2012

Building a Templated Web Site with - Part 3

In Part 1 of this series, I looked at how to turn an HTML page into a Visualforce page in order to use it as a template for a site.  Part 2 covered how to turn the page into a template and create a home page that used the template to provide the common content.  

Up to now the pages have only been available to users that have logged in to the Salesforce system. This post will show how to expose the pages in a site, to allow access from the wider web.

Before creating a site I have to choose my domain name - so I navigate to Setup -> App Setup -> Develop -> Sites and the following page is presented:

Screen Shot 2012 11 17 at 11 30 13

As I'm using a Free Edition org (yes, I was lucky enough to be able to grab a couple of these when they were available - I only wish I'd had the foresight to grab about 50!) I can't change the rather ugly default domain name, but in Enterprise/Unlimited Edition you can choose what you like, as long as someone else hasn't taken it.  I'm not stuck with this domain name however, as I can define a custom 'vanity' URL for my site, which I'll set up later.

Ticking the box and confirming that I understand I can't change the domain name, registers my domain and takes me to the back to the Sites page with my domain defined.

Screen Shot 2012 11 17 at 11 35 02

I then click the 'New' button to create my new site.  As this is for demo purposes only, I've filled in the minimum amount of information.  If you'd like more information on the purpose of each of these fields, check the help page by clicking the 'Help for this Page' link at the top right.

Screen Shot 2012 11 17 at 11 40 27

As I have specified my 'home' Visualforce page, this is automatically included in the list of pages for the site:

Screen Shot 2012 11 17 at 11 43 59

As an aside, whenever you add a Visualforce page to a site, your site automatically gets access to any Apex classes that it depends on. 

And that's it!  I can now navigate to the default site address and access my page without going through any form of authentication.

Screen Shot 2012 11 17 at 11 48 47

While my site is now available on the internet, the chances of anyone bothering to type in the full URL are pretty slim, so the next task is to set up the vanity URL. This has to be a CNAME redirect from my personal domain to the site domain name.  In my case I'm going to create a subdomain to of  My registration system is Freeparking, and I have to set up an alias to the A record in order for the CNAME record to be created:

Screen Shot 2012 11 17 at 12 09 25

I can then verify that my record has been created using an online nslookup tool:

Screen Shot 2012 11 17 at 12 18 09


Finally, update the site configuration to define the custom URL:

Screen Shot 2012 11 17 at 14 52 53

Sometimes the DNS records don't propagate for a while, so if the vanity URL doesn't work, give it a couple of hours and try again.

Accessing my site via shows that everything is set up correctly and propagated:


Screen Shot 2012 11 17 at 14 56 01

In the next post I'll add pages for one or two of the other tabs and show one way to highlight the tab associated with the page.



No comments:

Post a Comment