3

I have a callout where we use a Named Credential and it looks something like the following:

public class MyClass
{
    public MyClass()
    {
        inputHttpHeaders_x = new Map<String, String>
        {
            'Authorization' => 'Basic {!$Credential.AuthorizationHeaderValue}'
        };
    }
    public SomeType makeCallout(/*parameters*/)
    {
        WebServiceCallout.invoke(
            this,
            request_x,
            response_map_x,
            new String[]{
                'callout:My_Credential'
                // other parameters
            }
        );
    }
}

Notice I am using an endpoint of callout:My_Credential and using $Credential.AuthorizationHeaderValue in my Authorization header.

This callout worked great in the development sandbox. When we deployed it to UAT along with the Named Credential, however, it didn't work. We were getting a 401 response. I changed the header to hard code the token and the callout worked, so it looked like a password issue. I edited the Named Credential record to reset the password to exactly what it was in the development environment, and the problem was resolved.

Do Named Credential records deploy without Password being populated? Or does the $Credential.AuthorizationHeaderValue just not get carried through? Is it possible to deploy a credential with either of these values intact?

  • A named credential metadata retrieve doesn't include the password, but one can be included in the metadata when it's deployed to the target org. – Mark Pond Aug 14 '18 at 19:40
  • Possible duplicate of Migrating Named Credential with password – Mark Pond Aug 14 '18 at 19:40
  • 1
    I'm not asking about ANT (using Change Sets). Still, I guess the answer is just "no". – Adrian Larson Aug 14 '18 at 19:46
  • Yes. Sounds like it needs to be a post-deployment step for your process. – Mark Pond Aug 14 '18 at 19:49
  • 1
    The Spring 15 release notes (when Named Credential became packageable and change-set-able) specify that the Credential must be re-authorized after installation from a package. In my experience, the same thing is true for change set deployments, but I've never seen it documented explicitly. – David Reed Aug 14 '18 at 20:01
4

A retrieve of Named Credential metadata does not include the sensitive field data, including password.

That said, password data can be included in metadata during the deployment and the password will be set in the target org.

<?xml version="1.0" encoding="UTF-8"?>
<NamedCredential xmlns="http://soap.sforce.com/2006/04/metadata">
    <endpoint>https://your.endpoint.url</endpoint>
    <label>endpoint_name</label>
    <principalType>NamedUser</principalType>
    <protocol>Password</protocol>
    <password>actual_password</password>
    <username>user@example.com</username>
</NamedCredential>

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.