I am having an issue when attempting to reference the {!$Credential.UserName}
and {!$Credential.Password}
merge fields.
I created a named credential with the following configuration:
- Identity Type: Named Principal
- Authentication Protocol: Password Authentication
- Generate Authorization Header: false
- Allow Merge Fields in HTTP Header: true
- Allow Merge Fields in HTTP Body: false
I also set the username and password as the credentials expected by our vendor's API. I then define the Authorization Header keys in Apex and use the merge fields as reference.
req.setHeader('Authorization-UserName', '{!$Credential.UserName}');
req.setHeader('Authorization-Token', '{!$Credential.Password}');
I initially hard-coded the Authorization-UserName and Authorization-Token (which worked). I am also using the same endpoint that was defined in Remote Site Settings. But due to the fact that I plan to use Named Credentials, I disabled the end point in Remote Site Settings (see: Create Named Credentials to Define Callout Endpoints and Their Authentication Settings). It appears that the {!$Credential.UserName}
is not resolving to the defined username value.
{!$Credential.Password}
merges properly?