1

I am trying to create a CustomObject using the WSDL metadata API. I'm getting this error Element {http://soap.sforce.com/2006/04/metadata}type invalid at this location in type CustomObject when I run the requests.

This is my SOAP Request

<env:Envelope
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:tns="http://soap.sforce.com/2006/04/metadata"
    xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
    <env:Header>
        <tns:SessionHeader>
            <tns:sessionId>005...p</tns:sessionId>
        </tns:SessionHeader>
    </env:Header>
    <env:Body>
        <tns:createMetadata
            xmlns="http://soap.sforce.com/2006/04/metadata">
            <tns:metadata xsi:type="CustomObject">
                <tns:type>CustomObject</tns:type>
                <tns:fullName>My2CustomOjbect</tns:fullName>
                <tns:label>API_CUS_OBJECT</tns:label>
                <tns:nameField>
                    <tns:label>Id</tns:label>
                    <tns:type>AutoNumber</tns:type>
                </tns:nameField>
                <tns:visibility>Public</tns:visibility>
            </tns:metadata>
        </tns:createMetadata>
    </env:Body>
</env:Envelope>">

Thanks.

1 Answer 1

2

you don't need to specify type as a separete tag. You are already defining it in metadata tag. So your body should be as the following:

<env:Body>
    <tns:createMetadata
        xmlns="http://soap.sforce.com/2006/04/metadata">
        <tns:metadata xsi:type="CustomObject">
            <tns:fullName>My2CustomOjbect</tns:fullName>
            <tns:label>API_CUS_OBJECT</tns:label>
            <tns:nameField>
                <tns:label>Id</tns:label>
                <tns:type>AutoNumber</tns:type>
            </tns:nameField>
            <tns:visibility>Public</tns:visibility>
        </tns:metadata>
    </tns:createMetadata>
</env:Body>
1
  • Thanks a lot for the response, that fixed my issue. Commented Mar 26, 2020 at 16:08

You must log in to answer this question.

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