6

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 '16 at 2:29
2

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">
    <active>true</active>
    <allowHomePage>false</allowHomePage>
    <allowStandardAnswersPages>false</allowStandardAnswersPages>
    <allowStandardIdeasPages>false</allowStandardIdeasPages>
    <allowStandardLookups>false</allowStandardLookups>
    <allowStandardSearch>false</allowStandardSearch>
    <authorizationRequiredPage>Unauthorized</authorizationRequiredPage>
    <bandwidthExceededPage>BandwidthExceeded</bandwidthExceededPage>
    <clickjackProtectionLevel>SameOriginOnly</clickjackProtectionLevel>
    <fileNotFoundPage>FileNotFound</fileNotFoundPage>
    <genericErrorPage>Exception</genericErrorPage>
    <inMaintenancePage>InMaintenance</inMaintenancePage>
    <inactiveIndexPage>InMaintenance</inactiveIndexPage>
    <indexPage>InMaintenance</indexPage>
    <masterLabel>unique site name xx</masterLabel>   <!-- CHange this to unique_site_name_xx -->
    <requireHttps>false</requireHttps>
    <requireInsecurePortalAccess>false</requireInsecurePortalAccess>
    <siteAdmin>atul@Trailhead.com</siteAdmin>
    <siteTemplate>SiteTemplate</siteTemplate>
    <siteType>Visualforce</siteType>
    <subdomain>pro1-developer-edition</subdomain>    <!-- CHange this to your domain name -->
</CustomSite>

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">
    <types>
        <members>*</members>
        <name>CustomSite</name>
    </types>
    <version>36.0</version>
</Package>

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

https://github.com/financialforcedev/apex-mdapi

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.