3

I wanna change the homepage of a Force.com Site using the Metadata API. Nothing fancy, so:

  • I've prepared a new updateMetadata request,
  • set fullName to the API name of the site,
  • put indexPage to the Visualforce Page,
  • populate the other "required fields",

Then POST all that to the SOAP endpoint. But the response is a little bit confuzzling for me:

DUPLICATE_VALUE: A site with those parameters is already in use.

I guess it's true, the CustomSite exists, I want to update it. What am I missing here?

curl \
-X POST 'https://na1.salesforce.com/services/Soap/m/34.0' \
--header 'Content-Type: text/xml' \
--header 'SoapAction: ""' \
--data @request.xml

(request)
<?xml version="1.0" encoding="utf-8"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <env:Header>
        <urn:SessionHeader xmlns:urn="http://soap.sforce.com/2006/04/metadata">
            <urn:sessionId>{session_id}</urn:sessionId>
        </urn:SessionHeader>
    </env:Header>
    <env:Body>
        <updateMetadata xmlns="http://soap.sforce.com/2006/04/metadata">
            <metadata xsi:type="CustomSite">
                <fullName>site_name</fullName>
                <indexPage>MySiteHomePage</indexPage>
                <clickjackProtectionLevel>SameOriginOnly</clickjackProtectionLevel>
                <masterLabel>my site label</masterLabel>
                <siteType>Visualforce</siteType>
                <requireHttps>false</requireHttps>
            </metadata>
        </updateMetadata>
    </env:Body>
</env:Envelope>

(response)
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://soap.sforce.com/2006/04/metadata">
    <soapenv:Body>
        <updateMetadataResponse>
            <result>
                <errors>
                    <message>A site with those parameters is already in use.</message>
                    <statusCode>DUPLICATE_VALUE</statusCode>
                </errors>
                <fullName>site_name</fullName>
                <success>false</success>
            </result>
        </updateMetadataResponse>
    </soapenv:Body>
</soapenv:Envelope>

1 Answer 1

4

Ack, added the urlPathPrefix tag to the request and found the problem:

The metadata definition must contain all fields applicable to the type, eg:

<metadata xsi:type="CustomSite">
    <fullName>site_name</fullName>
    <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>
    <customWebAddresses>
        <domainName>www.mydomain.com</domainName>
        <primary>true</primary>
    </customWebAddresses>
    <fileNotFoundPage>FileNotFound</fileNotFoundPage>
    <genericErrorPage>Exception</genericErrorPage>
    <inMaintenancePage>InMaintenance</inMaintenancePage>
    <indexPage>HomePage</indexPage>
    <masterLabel>site label</masterLabel>
    <requireHttps>false</requireHttps>
    <requireInsecurePortalAccess>false</requireInsecurePortalAccess>
    <siteAdmin>[email protected]</siteAdmin>
    <siteTemplate>MySiteTemplate</siteTemplate>
    <siteType>Visualforce</siteType>
    <subdomain>subdomain</subdomain>
    <urlPathPrefix>path</urlPathPrefix>
</metadata>

If any of the above fields are absent, they will be overwritten with nulls.

You must log in to answer this question.

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