2

We are connecting Salesforce from a third-party system, the requirement is to create some named credentials, custom metadata records, and remote site settings from the third-party System after installation of the managed package.

I am trying to create a named credential in Salesforce through SOAP metadata API. I am using Salesforce Platform APIs on Postman. Below is my request body.

Request Body

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://soap.sforce.com/2006/04/metadata">
    <soapenv:Header>
        <tns:SessionHeader>
            <tns:sessionId>{{_accessToken}}</tns:sessionId>
        </tns:SessionHeader>
    </soapenv:Header>
    <soapenv:Body>
        <tns:createMetadata>
            <tns:metadata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="tns:NamedCredential">
                <endpoint>https://your.endpoint.url</endpoint>
                <label>endpoint_name</label>
                <principalType>NamedUser</principalType>
                <protocol>Password</protocol>
                <password>actual_password</password>
                <username>[email protected]</username>
            </tns:metadata>
        </tns:createMetadata>
    </soapenv:Body>
</soapenv:Envelope>

This is the response I am getting.

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" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
        <createMetadataResponse>
            <result>
                <fullName xsi:nil="true"/>
                <success>false</success>
            </result>
        </createMetadataResponse>
    </soapenv:Body>
</soapenv:Envelope>

The response does not give any descriptive information about the problem here. I am not able to create the NamedCredential.

What am I doing wrong here?

1 Answer 1

2

Here the metadata request is missing the fullName attribute. This will work:

(Security review constraints will apply for a third-party, but the SOAP is valid...)

<?xml version="1.0" encoding="utf-8"?>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Header>
        <SessionHeader xmlns="http://soap.sforce.com/2006/04/metadata">
            <sessionId>{access_token_here}</sessionId>
        </SessionHeader>
    </Header>
    <Body>
        <createMetadata xmlns="http://soap.sforce.com/2006/04/metadata">
            <metadata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="NamedCredential">
                <fullName>Demo_Integration</fullName>
                <endpoint>https://your.endpoint.url</endpoint>
                <label>endpoint_name</label>
                <principalType>NamedUser</principalType>
                <protocol>Password</protocol>
                <password>actual_password</password>
                <username>[email protected]</username>
            </metadata>
        </createMetadata>
    </Body>
</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>
        <createMetadataResponse>
            <result>
                <fullName>Demo_Integration</fullName>
                <success>true</success>
            </result>
        </createMetadataResponse>
    </soapenv:Body>
</soapenv:Envelope>
1
  • 1
    Well the sample in your answer is a little different but adding fullName fixed my problem, thank you very much. Commented Jan 11 at 13:09

You must log in to answer this question.

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