The Metadata API allows us to programatically list all the current public facing sites in an org. There is a class called CustomSite covering this element.

Has anybody ever successfully created a new public facing site, using the Metadata API?

My end goal is I'd like to let my customers create a site from a custom setup page.

Thank you!

  • Nice question! Well asked. Welcome to SFSE.
    – Adrian Larson
    Mar 13, 2016 at 2:29

1 Answer 1


This question is really interesting. I have used MD API for other purpose but not creating site.

So, just to make sure my solution work i have tested it with workbench and sure it worked.

So, Here are steps.

1) Create folder name "package"
2) In that create "sites" folder
3) In "sites" folder create file name "unique_site_name_xx.site"
4) Enter below XML in that.

<?xml version="1.0" encoding="UTF-8"?>
<CustomSite xmlns="http://soap.sforce.com/2006/04/metadata">
    <masterLabel>unique site name xx</masterLabel>   <!-- CHange this to unique_site_name_xx -->
    <siteAdmin>[email protected]</siteAdmin>
    <subdomain>pro1-developer-edition</subdomain>    <!-- CHange this to your domain name -->

5) Now create package.xml in "package" folder with following code.

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">

6) Now zip package folder. Here is sample zip for your reference https://atuldev-dev-ed.my.salesforce.com/sfc/p/280000011nkh/a/280000008bQP/yyOQnx4BwSNmqWBvZ.HHhHdrNRJ6I.PGTXKhmwKNLFk 7) Go to workbranch and navigate to migration -> Deploy upload the zip
you will see the success status

Now you need to convert all these steps in apex to provide the UI.

You should also note that you will not be able to create zip on SFDC so you will need to use external system to do this.

I would suggest you create web service in php(or other langue) to generate zip. Call this web service from Apex and get the zip and then pass it to Deploy API

Here are few sample links that shows how to call of MD API https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_quickstart_java_sample.htm

PS: Make sure set domain before trying this solution


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .