Use Named Credential Formula Functions in Custom Headers
Formula functions can be used in the value field of a custom header of a named credential or external credential.
Required Editions
| Available in: both Salesforce Classic (not available in all orgs) and Lightning Experience |
| Available in: all editions |
A binary large object (BLOB) is a collection of binary data stored as a single entity. For named credentials, BLOBs can store binary executable code used in custom header formulas. See Create and Edit Custom Headers.
Formula fields can contain up to 3,900 characters, including spaces, return characters, and comments. If your formula requires more characters, create separate formula fields and reference them in another formula field. The maximum number of displayed characters after an evaluation of a formula expression is 1,300, which can truncate access tokens in custom headers.
| Function | Description |
|---|---|
| BASE64DECODE(expr) |
|
| BASE64ENCODE(expr) |
|
| BLOB(expr) |
|
| HASH(algorithm, expr) |
|
| HEX(expr) |
|
| HMAC(algorithm, valueToSign, secretSigningKey) |
|
| SIGN(algorithmName, input, privateKey) |
|
| SIGN_WITH_CERTIFICATE(algorithmName, input, certDevName) |
|
Examples
-
This example shows encoding a username and password stored in an external credential. The
BLOBfunction first converts a string of form username:password into a binary.BASE64ENCODEthen converts the binary into an encoded string.myExternalCredentialis the name of an external credential.BASE64ENCODE(BLOB($Credential.myExternalCredential.Username & ':' & $Credential.myExternalCredential.Password)) -
This example sets a header named
X-Usernamewith a base-16, SHA-256-hashed username as the value.reqis anHTTPRequest.Usernameis an authentication parameter attached to a principal.req.setHeader('X-Username', '{!HEX(HASH(\'SHA-256\', BLOB($Credential.myExternalCredential.Username)))}'); -
This example sets the
X-Bodyheader as the base-16, hashed evaluated body, meaning that all formulas within the request body are evaluated.BLOBisn’t required here because$Credential.myExternalCredential.Bodyis returned as a BLOB type rather than as a String.req.setHeader('X-Body', '{!HEX(HASH(\'SHA-256\', $Credential.myExternalCredential.Body))}');

