---
schema_version: "1"
id: b908ca38a3af941d1b56b468d04520e49b0e88bf293f049680f1c9abfbb63e9b
title: Named Credential Formula Functions
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/security/named-credentials/references/about/nc-formula-functions.md
canonical_url: https://developer.salesforce.com/docs/platform/named-credentials/references/named-credentials-reference/nc-formula-functions.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 1cb2da08bb92b4e8e1880ec00fa9c516795eb999ef650861fcf68d4f50a229b4
products:
  - Named Credentials
  - Security
---
# Named Credential Formula Functions

Formula functions can be used in the value field of a custom header of a named credential or external credential.

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.

## Formula Functions

| Function                                         | Description                                                                                                                                                                                                                                                                                                     |
| ------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| BASE64DECODE(_expr_)                             | <ul><li>**Input:** String</li><li>**Output:** BlobValue</li><li>**Description:** Decode the Base64-encoded String expression to binary.</li></ul>                                                                                                                                                               |
| BASE64ENCODE(_expr_)                             | <ul><li>**Input:** BlobValue</li><li>**Output:** String</li><li>**Description:** Encode the binary BLOB expression as a Base64-encoded String.</li></ul>                                                                                                                                                        |
| BLOB(_expr_)                                     | <ul><li>**Input:** String</li><li>**Output:** BlobValue</li><li>**Description:** Convert the value to a UTF-8 binary BLOB.</li></ul>                                                                                                                                                                            |
| HASH(_algorithm, expr_)                          | <ul><li>**Input:** String, BlobValue</li><li>**Output:** BlobValue</li><li>**Description:** Given a binary value to hash, use _algorithm_ to get the binary hash. The only supported hashing algorithm is SHA-256.</li></ul>                                                                                    |
| HEX(_expr_)                                      | <ul><li>**Input:** BlobValue</li><li>**Output:** String</li><li>**Description:** Represents the given BLOB expression as a base-16 lower-case encoded String. This hex encoding contains the binary data expected by encryption functions.</li></ul>                                                            |
| HMAC(_algorithm, valueToSign, secretSigningKey_) | <ul><li>**Input:** String, BlobValue, BlobValue</li><li>**Output:** BlobValue<</li>li>**Description:** Use _algorithm_ to sign the given binary _valueToSign_ with a binary secret signing key. The resulting message authentication code is a binary value. The only supported algorithm is SHA-256.</li></ul> |

## Examples

- This example shows encoding a username and password stored in an external credential. The `BLOB` function first converts a string of form _username_:_password_ into a binary. `BASE64ENCODE` then converts the binary into an encoded string. `myExternalCredential` is the name of an external credential.

```
BASE64ENCODE(BLOB($Credential.myExternalCredential.Username &amp; ':' &amp; $Credential.myExternalCredential.Password))
```

- This example sets a header named `X-Username` with a base-16, SHA-256-hashed username as the value. `req` is an HTTPRequest. `Username` is an authentication parameter attached to a permission set mapping.

```
req.setHeader('X-Username', '{!HEX(HASH(\'SHA-256\', BLOB($Credential.myExternalCredential.Username)))}');
```

- This example sets the X-Body header as the base-16, hashed _evaluated_ body, meaning that all formulas within the request body are evaluated. `BLOB` isn’t required here because `$Credential.myExternalCredential.Body` is returned as a BLOB type, rather than as a String.

```
req.setHeader('X-Body', '{!HEX(HASH(\'SHA-256\', $Credential.myExternalCredential.Body))}');
```
