---
schema_version: "1"
id: 0c4b28eebe7c5d690e0c597c2e67ccb6e09064fbc59da6adf89c0afcf10f96d6
title: Use Named Credential Formula Functions in Custom Headers
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/xcloud/264-0-0/nc_named_creds_formula_functions.md
canonical_url: https://help.salesforce.com/s/articleView?id=xcloud.nc_named_creds_formula_functions.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 435a430bfb2c5939048393aa24607e0e8f5109de0b0f2f831ee2631094c6ee6c
description: Formula functions can be used in the value field of a custom header of a named credential or external credential.
products:
  - Security
release: "264"
---
# 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

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: both Salesforce Classic (not available in all orgs) and Lightning Experience</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: all editions</td></tr></tbody></table>

![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-xcloud-security-264-0-0-production-enus/8cecd769-ab2d-4e07-addf-c4f2927925e1/images/icon_note.png)

Note Not all Salesforce formula functions are supported for named and external credential custom headers. We recommend using these formula functions for authentication use cases.

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](https://help.salesforce.com/s/articleView?id=xcloud.nc_create_custom_headers.htm&release=264.0.0&type=5 "Use custom headers to make unique secure connections to external data sources.").

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.

Formula Functions for Named Credentials  
| Function | Description |
| --- | --- |
| BASE64DECODE(expr) | 
Input

String

Output

BlobValue

Description

Decode the Base64-encoded String expression to a binary.



 |
| BASE64ENCODE(expr) | 

Input

BlobValue

Output

String

Description

Encode the binary BLOB expression as a Base64-encoded String.



 |
| BLOB(expr) | 

Input

String

Output

BlobValue

Description

Convert the value to a UTF-8 binary BLOB.



 |
| HASH(algorithm, expr) | 

Input

String, BlobValue

Output

BlobValue

Description

Given a binary value to hash, use algorithm to get the binary hash.

The only supported hashing algorithm is SHA-256.



 |
| HEX(expr) | 

Input

BlobValue

Output

String

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.



 |
| HMAC(algorithm, valueToSign, secretSigningKey) | 

Input

String, BlobValue, BlobValue

Output

BlobValue

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.



 |
| SIGN(algorithmName, input, privateKey) | 

Input

String, BlobValue, BlobValue

Output

BlobValue

Description

Compute a unique digital signature for the input string using the specified algorithm and private key.

Supported algorithms are RSA, RSA-SHA1, RSA-SHA256, RSA-SHA384, RSA-SHA512, ECDSA-SHA256, ECDSA-SHA256-PLAIN, ECDSA-SHA384, and ECDSA-SHA512.



 |
| SIGN\_WITH\_CERTIFICATE(algorithmName, input, certDevName) | 

Input

String, BlobValue, String

Output

BlobValue

Description

Compute a unique digital signature for the input string using the specified algorithm and the unique name of a certificate in the Salesforce org.

Supported algorithms are RSA, RSA-SHA1, RSA-SHA256, RSA-SHA384, RSA-SHA512, ECDSA-SHA256, ECDSA-SHA256-PLAIN, ECDSA-SHA384, and ECDSA-SHA512.



 |

## 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 & ':' & $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 principal.
    
    ```
    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))}');
    ```

#### See Also

- [Use Custom Headers for Basic Authentication with Named Credentials](https://help.salesforce.com/s/articleView?id=xcloud.nc_custom_headers_basic_auth.htm&release=264.0.0&type=5 "Create an external credential with a custom header that uses HTTP Basic authentication.")
- [Formula Operators and Functions by Context](https://help.salesforce.com/s/articleView?id=platform.customize_functions.htm&type=5&language=en_US)
- [Calculate Field Values With Formulas](https://help.salesforce.com/s/articleView?id=platform.customize_formuladef.htm&type=5&language=en_US)
- [_Apex Developer Guide_: Merge Fields for Apex Callouts That Use Named Credentials](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts_named_credentials_merge_fields.htm)