Recipes by Category

App Distribution (2) Bundle logic, interface and services for distribution. App Logic (37) The Apex programming language, workflow and formulas for logic. Collaboration (5) The Salesforce Chatter collaboration platform. Database (29) Data persistence, reporting and analytics. Integration (33) Web Service APIs and toolkits for integration. Security (9) Platform, application and data security. Tools (4) tooling User Interface (36) Visualforce MVC and metadata-drive user interfaces. Web Sites (12) Public web sites and apps with optional user registration and login.
Beta Feedback
Cookbook Home » Creating a Sitemap File

Creating a Sitemap File

Post by Developer Force  (2010-07-16)

Status: Certified
Level: novice


You want to improve the volume and quality of traffic to your site.


For sites with a large number of dynamic pages that are only available through the use of forms and user entries, you can create a sitemap, which lists the pages on your site that are accessible to Web crawlers and users. The Google, Bing, Yahoo!, and Ask search engines support the sitemaps protocol. For more information on sitemaps and the sitemap protocol, see

To create a sitemap, you'll create a Visualforce sitemap page with text or XML content type, and populate the URLs in XML format. Then, to submit the sitemap to Web crawlers, you'll create a robots.txt file, adding the path to your sitemap.

First, create the sitemap:

  1. Click Setup | Develop | Pages.
  2. Click New.
  3. For the Label and Name, enter Sitemap.
  4. Replace the existing Visualforce markup with the following, substituting the example URLs with your site's URLs:
<apex:page contentType="text/xml">

<!-- created with Free Online Sitemap Generator -->  

<!-- Replace the following URL with the site URL that you want
     to be mapped and accessible to Web crawlers. -->  
<!-- Replace the following URLs with your site's actual URLs -->  
Alternatively, you can dynamically create your sitemap page content using a controller, and enable this page for your site.

Then enable the page for your site:

  1. Click Setup | Develop | Sites and click your site name.
  2. In the Site Visualforce Pages list, click Edit.
  3. Under Available Visualforce Pages, select Sitemap and click Add.
  4. Click Save.

Finally, create and enable the robots.txt file:

  1. Click Setup | Develop | Pages.
  2. Click New.
  3. For the Label and Name, enter robots.
  4. Replace the existing Visualforce markup with the following, substituting the example URL with your site's path and sitemap name:
    <apex:page contentType="text/plain">
       User-Agent: *
       Allow: /
    <!-- Replace this path with your site's actual
         path and sitemap name. -->
  5. Click Setup | Develop | Sites.
  6. Click Edit for your site.
  7. In the Site Robots.txt box, enter robots.
  8. Click Save.
Alternatively, you can submit the URL as a sitemap via a Google Webmaster Tools account.


Recipe Activity - Please Log in to write a comment

Remember you can use global variables when including paths to pages, so in Robots you can just do:

sitemap: {!$Page.Sitemap}

by a093000000Wc7Qj  (2013-02-08)

Has anyone tried to have dynamically created sitemap. 

Sitemap does not show as an available visualforce page. Any other suggestions on how this should be created? Thanks

by a0930000009u182  (2011-04-17)

 Thanks Sonny -fixed.

by Jon Mountjoy  (2011-01-17)

 Hi Developer Force,

Any chance you could fix the second code sample of this page please? It is identical with the first one.



by sonninho  (2011-01-17)


Vote to Verify a Recipe

Verifying a recipe is a way to give feedback to others and broaden your own understanding of the capabilities on When you verify a recipe, please make sure the code runs, and the functionality solves the articulated problem as expected.

Please make sure:
  • All the necessary pieces are mentioned
  • You have tested the recipe in practice
  • Have sent any suggestions for improvements to the author

Please Log in to verify a recipe

You have voted to verify this recipe.