> For the complete documentation index, see [llms.txt](https://docs.work-relay.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.work-relay.com/automations/functions-and-formulas/functions-library/text-functions.md).

# Text functions

<details>

<summary>SPECIALSYMBOLS</summary>

Allows using of special symbols within the formula.

**Usage**:

`{QUOTE}` for single quote (`'`)\
`{DBL_QUOTE}` for double quote (`"`)\
`{OPEN_BKT}` for opening bracket (`(`)\
`{CLOSE_BKT}` for closing bracket (`)`)\
`{OPEN_SQR_BKT}` for opening square bracket (`[`)\
`{CLOSE_SQR_BKT}` for closing square bracket (`]`)\
`{TAB}` for tabulation\
`{BACK_SL}` for backslash (`</code>)`\
`{BR} for line break`\
`{RET} for carriage return`

*<mark style="color:cyan;">Use any of the expressions above whenever you need formula to contain special symbol(s).</mark>*

**Example**:

{% code overflow="wrap" %}

```apex
IF(STARTS({Request__c.Name}, 'RFQ'), '{OPEN_SQR_BKT}Request for Quote{CLOSE_SQR_BKT}', '{OPEN_SQR_BKT}Service{CLOSE_SQR_BKT}')
```

{% endcode %}

Returns **'\[Request for Quote]'** if request name starts with 'RFQ', and '**\[Service]'** if it doesn't.

</details>

<details>

<summary>CONTAINS</summary>

Compares two arguments of text and returns true if the first argument contains the second argument. If not, returns false.

**Usage**:

{% code overflow="wrap" %}

```apex
CONTAINS(source_string, search_string)
```

{% endcode %}

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`source_string`</mark>* *<mark style="color:cyan;">with the text that should be searched for a value of search\_string.</mark>*

**Example**:

{% code overflow="wrap" %}

```apex
IF(CONTAINS({Opportunity.Product_Type__c}, 'part'), 'Parts', 'Service')
```

{% endcode %}

Returns '**Parts**' for any Opportunity Product with the word 'part' in it's Type field. Otherwise, it returns '**Service**'.

</details>

<details>

<summary>STARTS</summary>

Determines whether a string begins with the characters of another string, returning true if it does. If not, returns false.

**Usage**:

{% code overflow="wrap" %}

```apex
STARTS(source_string, search_string)
```

{% endcode %}

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`source_string`</mark>* *<mark style="color:cyan;">with the text that should be checked for starting from the value of</mark>* *<mark style="color:cyan;">`search_string`</mark><mark style="color:cyan;">.</mark>*

**Example**:

{% code overflow="wrap" %}

```apex
IF(STARTS({Request__c.Name}, 'RFQ'), 'Request for Quote', 'Service')
```

{% endcode %}

Returns '**Request for Quote**' for any request name starting with 'RFQ'. Otherwise, it returns '**Service**'.

{% hint style="info" %}
Note: values are case sensitive.
{% endhint %}

</details>

<details>

<summary>POS</summary>

Gets the position of a string within another string and returns it as a number.

**Usage**:

{% code overflow="wrap" %}

```apex
POS(source_string, search_string)
```

{% endcode %}

*<mark style="color:cyan;">Replace:</mark>*

* *<mark style="color:cyan;">`source_string`</mark>* *<mark style="color:cyan;">with the field or expression you want to search in</mark>*
* *<mark style="color:cyan;">`search_string`</mark>* *<mark style="color:cyan;">with the string you want to find</mark>*

**Example**:

{% code overflow="wrap" %}

```apex
POS({Contact.Email}, '@')
```

{% endcode %}

Returns position of the '@' symbol in a person's email address.

</details>

<details>

<summary>ENDS</summary>

Determines whether a string ends with the characters of another string, returning **true** if it does. If not, returns **false**.

**Usage:**

{% code overflow="wrap" %}

```apex
ENDS(source_string, search_string)
```

{% endcode %}

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`source_string`</mark>* *<mark style="color:cyan;">with the text that should be checked for ending with the value of</mark>* *<mark style="color:cyan;">`search_string`</mark><mark style="color:cyan;">.</mark>*

**Example:**

{% code overflow="wrap" %}

```apex
IF(ENDS({Company__c.Name}, 'TM'), 'Trademark', 'Service mark')
```

{% endcode %}

Returns '**Trademark**' for any item ending with 'TM'. Otherwise, it returns '**Service mark**'.

{% hint style="warning" %}
Note: values are case sensitive.
{% endhint %}

</details>

<details>

<summary>SUBSTR</summary>

Returns a new string that begins with the character at the specified zero-based `start_index` position and extends until the character at `end_index` position.

**Usage:**

{% code overflow="wrap" %}

```apex
SUBSTR(source_string, start_index, end_index)
```

{% endcode %}

*<mark style="color:cyan;">Replace:</mark>*

* *<mark style="color:cyan;">`source_string`</mark>* *<mark style="color:cyan;">with the string, field or expression where you want to get a substring from</mark>*
* *<mark style="color:cyan;">`start_index`</mark>* *<mark style="color:cyan;">with position which substring begins from</mark>*
* *<mark style="color:cyan;">`end_index`</mark>* *<mark style="color:cyan;">with position which substring ends before</mark>*

**Example:**

{% code overflow="wrap" %}

```apex
SUBSTR({Contact.Name}, 4, 8) 
```

{% endcode %}

Returns '**erso**' when Contact.Name equals 'Jefferson'.

{% hint style="info" %}
Function returns a substring starting FROM `start_index` position UNTIL `end_index` (starting with a symbol at `start_index` position, and ending with `end_index - 1` position).

Indexes are counted from 0.
{% endhint %}

</details>

<details>

<summary>REPLACE</summary>

Replaces a sequence of characters in a string with another set of characters, and returns a resulting string.

**Usage**:

{% code overflow="wrap" %}

```apex
REPLACE(source_string, from_string, to_string, regex_boolean_optional)
```

{% endcode %}

*<mark style="color:cyan;">Replace:</mark>*

* *<mark style="color:cyan;">`source_string`</mark>* *<mark style="color:cyan;">with string to be changed</mark>*
* *<mark style="color:cyan;">`from_string`</mark>* *<mark style="color:cyan;">with characters to be replaced in source\_string</mark>*
* *<mark style="color:cyan;">`to_string`</mark>* *<mark style="color:cyan;">with the replacement set of characters</mark>*

**Example 1:**

{% code overflow="wrap" %}

```apex
REPLACE({Opportunity.Unique_ID__c}, '3a', '2b') 
```

{% endcode %}

Returns: in this example the `Unique_ID__c` will now contain new value with the '**3a**' replaced with '**2b**'.

**Example 2:**

User can pass regular expression as a `from_string` argument as well. In this case user should add 'true' as an optional `regex_boolean_optional` argument.

{% code overflow="wrap" %}

```apex
REPLACE('a3f45qq456', '[^0-9]', '', true) 
```

{% endcode %}

Returns **345456**.

</details>

<details>

<summary>REMOVE</summary>

Removes one or more substrings from a source string.

**Usage:**

{% code overflow="wrap" %}

```apex
REMOVE(source_string, string_parameter1, string_parameter2, ...) 
```

{% endcode %}

*<mark style="color:cyan;">Replace:</mark>*

* *<mark style="color:cyan;">`source_string`</mark>* *<mark style="color:cyan;">with the text field or expression you want to remove substrings from</mark>*
* *<mark style="color:cyan;">`string_parameter1`</mark><mark style="color:cyan;">,</mark>* *<mark style="color:cyan;">`string_parameter2`</mark><mark style="color:cyan;">, etc with substrings to be removed from the</mark>* *<mark style="color:cyan;">`source string`</mark>*

**Example:**

{% code overflow="wrap" %}

```apex
REMOVE('(555) 555-6789 ', ' ', '(', ')', '-')
```

{% endcode %}

Returns '**5555556789**'.

</details>

<details>

<summary>LEN</summary>

Returns the number of characters in a specified text string (string length).

**Usage:**

{% code overflow="wrap" %}

```apex
LEN(string)
```

{% endcode %}

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`string`</mark>* *<mark style="color:cyan;">with the field or expression which length you want get.</mark>*

**Example:**

{% code overflow="wrap" %}

```apex
LEN({Product__с.Code__c}) 
```

{% endcode %}

Returns the length of a Product.Code field.

</details>

<details>

<summary>SPLIT</summary>

Returns an array (a list) that contains each substring of the source stringthat is split on `split_by_string` parameter. Substrings are placed in the array in the order in which they occur in the source string.

**Usage:**

```apex
SPLIT(source_string, separator_string)
```

*<mark style="color:cyan;">Replace:</mark>*

* *<mark style="color:cyan;">`source_string`</mark>* *<mark style="color:cyan;">with the text field or expression to be split</mark>*
* *<mark style="color:cyan;">`separator_string`</mark>* *<mark style="color:cyan;">with a substring to split on</mark>*

**Example:**

```apex
SPLIT('AL, AK, AZ, AR', ', ')
```

Returns an array that of elements of string type.

</details>

<details>

<summary>JOIN</summary>

Joins the elements of an array into a single string separated by the specified separator.

**Usage:**

```apex
JOIN(array, separator_string, left_string_optional, right_string_optional)
```

*<mark style="color:cyan;">Replace:</mark>*

* *<mark style="color:cyan;">`array`</mark>* *<mark style="color:cyan;">with an array you want to join to a string</mark>*
* *<mark style="color:cyan;">`separator_string`</mark>* *<mark style="color:cyan;">with the separator. Use the optional arguments to add text around each element</mark>*

**Example:**

<mark style="color:orange;">Let</mark> <mark style="color:orange;">`String__c`</mark> <mark style="color:orange;">field on</mark> <mark style="color:orange;">`Stub__c`</mark> <mark style="color:orange;">object stores following string: 'Cars, Plains, Ships'.</mark>

```
{OPEN_SQR_BKT} + JOIN(SPLIT({Stub__c.String__c}, ','), ',', '{DBL_QUOTE}', '{DBL_QUOTE}') + {CLOSE_SQR_BKT} 
```

Returns: **'\["Cars", "Plains", "Ships"]'** (this formula will split field value to an array and then transform it to a string).

</details>

<details>

<summary>LOWER</summary>

Converts all of the characters in the string to lowercase.

**Usage:**

```apex
LOWER(string)
```

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`string`</mark>* *<mark style="color:cyan;">with the value to convert to lowercase.</mark>*

**Example:**

```apex
LOWER({Account.Name})
```

Returns account name value in lowercase.

</details>

<details>

<summary>UPPER</summary>

Converts all of the characters in the string to uppercase.

**Usage:**

```apex
UPPER(string)
```

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`string`</mark>* *<mark style="color:cyan;">with the value to convert to uppercase.</mark>*

**Example:**

```apex
UPPER({Account.Name})
```

Returns account name value in uppercase.

</details>

<details>

<summary>ESCAPE</summary>

Returns a string whose characters are escaped using specified rule.

**Usage:**

{% code overflow="wrap" %}

```apex
ESCAPE(string,JAVA|JSON|HTML|CSV|XML|UNICODE|QUOTE)
```

{% endcode %}

*<mark style="color:cyan;">Pass</mark>* *<mark style="color:cyan;">`string`</mark>* *<mark style="color:cyan;">to be escaped and one of the allowed escape rules as arguments.</mark>*

**Examples:**

<mark style="color:orange;">Let</mark> <mark style="color:orange;">`Stub__c.String__c`</mark> <mark style="color:orange;">value is 'Please, fill in "Name"'.</mark>\
\
`ESCAPE({Stub__c.String__c}, 'HTML')` will return **'Please, fill in quot;Namequot;**'\
\
`ESCAPE({Stub__c.String__c}, 'JAVA')` will return '**Please, fill in "Name"**'\
\
`ESCAPE({Stub__c.String__c}, 'CSV')` will return '**"Please, fill in ""Name"""**'\
\
`ESCAPE({Stub__c.String__c}, 'XML')` will return '**Please, fill in quot;Namequot;**'

\ <mark style="color:orange;">Let</mark> <mark style="color:orange;">`Stub__c.String__c`</mark> <mark style="color:orange;">value is 'De onde você é?'</mark>

`ESCAPE({Stub__c.String__c}, 'UNICODE')` will return '**De onde voc\u00EA \u00E9?**'

<mark style="color:orange;">Let</mark> <mark style="color:orange;">`Stub__c.String__c`</mark> <mark style="color:orange;">value is 'De onde você é?'</mark>

`ESCAPE({Stub__c.String__c}, 'UNICODE')` will return '**De onde voc\u00EA \u00E9?**'

</details>

<details>

<summary>UNESCAPE</summary>

Returns a string whose characters are unescaped using specified rule.

**Usage:**

{% code overflow="wrap" %}

```apex
UNESCAPE(string,JAVA|JSON|HTML|CSV|XML|UNICODE|QUOTE)
```

{% endcode %}

*<mark style="color:cyan;">Pass</mark>* *<mark style="color:cyan;">`string`</mark>* *<mark style="color:cyan;">to be unescaped and one of the allowed unescape rules as arguments.</mark>*

**Examples:**

`UNESCAPE('Please, fill in quot;Namequot;', 'HTML')` will return '**Please, fill in "Name"**'\
\
`UNESCAPE('Please, fill in "Name"', 'JAVA')` will return '**Please, fill in "Name"**'\
\
`UNESCAPE('"Please, fill in ""Name"""', 'CSV')` will return '**Please, fill in "Name"**'\
\
`UNESCAPE('Please, fill in quot;Namequot;', 'XML')` will return '**Please, fill in "Name"**'\
\
`UNESCAPE('De onde voc\u00EA \u00E9?', 'UNICODE')` will return '**De onde você é?**'

</details>

<details>

<summary>BR</summary>

Adds `<br>` (line break) HTML tag when used.

**Usage**:

<mark style="color:cyan;">Add</mark> <mark style="color:cyan;">`BR()`</mark> <mark style="color:cyan;">to other functions or output text values wherever you need a line break.</mark>

**Example:**

<mark style="color:orange;">Let</mark> <mark style="color:orange;">`Account.Account_Multy__c`</mark> <mark style="color:orange;">value is \[A, B, C] (these options had been checked).</mark>

{% code overflow="wrap" %}

```apex
JOIN(SPLIT({Account.Account_Multy__c}, ';'), BR()) 
```

{% endcode %}

Returns HTML string with line breaks (this formula will first split field value to an array and then transform it to a following text):

```apex
A
B
C
```

</details>

<details>

<summary>TEXT</summary>

Converts any data type into text.

**Usage:**

```apex
TEXT(parameter)
```

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`parameter`</mark>* *<mark style="color:cyan;">with the field or expression to convert to text.</mark>*

**Example:**

```apex
IF(TEXT({Stub__c.Number__c}) = {Stub__c.Text__c}, true, false)
```

Returns **true** when `Stub.Number` is 25 and `Stub.Text` is '25'.

{% hint style="success" icon="lightbulb-on" %}
This can be useful, e.g., it allows to compare numeric and string values.
{% endhint %}

</details>

<details>

<summary>BLOB</summary>

Casts the specified string to a [BLOB](https://en.wikipedia.org/wiki/Binary_large_object).

**Usage:**

```apex
BLOB(string)
```

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`string`</mark>* *<mark style="color:cyan;">with the value to cast to BLOB.</mark>*

**Example:**

```apex
BLOB({Account.LongTextField__c})
```

Returns the field value as BLOB content.

</details>

<details>

<summary>TOBASE64</summary>

Converts a BLOB to an unencoded String representing its normal form.

**Usage:**

```apex
TOBASE64(blob_parameter)
```

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`blob_parameter`</mark>* *<mark style="color:cyan;">with the BLOB content to convert to Base64.</mark>*

**Example:**

```apex
TOBASE64(BLOB({$Account.Name}))
```

Returns '**TWFyeSBBbm4=**' when `Account.Name` is 'Mary Ann'.

</details>

<details>

<summary>FROMBASE64</summary>

Converts a Base64-encoded string to a BLOB representing its normal form.

**Usage:**

```apex
FROMBASE64(string_parameter)
```

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`string_parameter`</mark>* *<mark style="color:cyan;">with a Base64-encoded string.</mark>*

**Example:**

```apex
FROMBASE64('TWFyeSBBbm4=')
```

Returns the BLOB content of 'Mary Ann'.

</details>

<details>

<summary>TOHEX</summary>

Returns a hexadecimal (base 16) representation of the string.

**Usage:**

```apex
TOHEX(string_parameter)
```

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`string_parameter`</mark>* *<mark style="color:cyan;">with the string to convert to hexadecimal.</mark>*

**Example:**

```apex
TOHEX({Account.Name})
```

Returns '**4d61727920416e6e**' when `Account.Name` is 'Mary Ann'.

</details>

<details>

<summary>FROMHEX</summary>

Converts the specified hexadecimal (base 16) value to text. Returns string.

**Usage:**

```apex
FROMHEX(string_parameter)
```

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`string_parameter`</mark>* *<mark style="color:cyan;">with the hexadecimal string to convert to text.</mark>*

**Example:**

```apex
FROMHEX('4d61727920416e6e')
```

Returns '**Mary Ann**'.

</details>

<details>

<summary>URLENCODE</summary>

Encodes or decodes a string in application/x-www-form-urlencoded format using a specific encoding scheme.

**Usage:**

```apex
URLENCODE(string_to_encode, format_optional, boolean_encode_optional)
```

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`string_to_encode`</mark>* *<mark style="color:cyan;">with the value to encode or decode.</mark>*\
*<mark style="color:cyan;">The</mark>* <mark style="color:cyan;">`format_optional`</mark> *<mark style="color:cyan;">defaults to</mark>* *<mark style="color:cyan;">`UTF-8`</mark><mark style="color:cyan;">.</mark>*\
*<mark style="color:cyan;">Pass</mark>* *<mark style="color:cyan;">`false`</mark>* *<mark style="color:cyan;">for</mark>* *<mark style="color:cyan;">`boolean_encode_optional`</mark>* *<mark style="color:cyan;">to decode.</mark>*

**Example 1:**

{% code overflow="wrap" %}

```apex
URLENCODE({Stub__c.String__c}) 
```

{% endcode %}

Returns '**Test+%2F+me**' when given String value is **'Test/me**'.

**Example 2:**

{% code overflow="wrap" %}

```apex
URLENCODE({Stub__c.String__c}, 'UTF-8', false) 
```

{% endcode %}

Returns '**Test/me**' when given String value is '**Test+%2F+me**'.

</details>

<details>

<summary>TOTEXTDURATION</summary>

Сonverts integer amount of minutes (numeric value) into string in the `XXXh YYm` or `ZZZd XXh YYm` format.

**Usage:**

{% code overflow="wrap" %}

```apex
TOTEXTDURATION(integer_minutes_parameter, hours_in_day_optional) 
```

{% endcode %}

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`integer_minutes_parameter`</mark>* *<mark style="color:cyan;">with integer representing number of minutes to get duration in hours and minutes.</mark>*\
*<mark style="color:cyan;">Add optional</mark>* *<mark style="color:cyan;">`hours_in_day_optional`</mark>* *<mark style="color:cyan;">argument to get duration in working days, hours and minutes.</mark>*

**Example 1:** `TOTEXTDURATION(6067)` will return '**101h 7m**'.\
\
**Example 2:** `TOTEXTDURATION(6067,8)` will return '**12d 5h 7m**', where each day has 8 hours (useful to calculate how many business days will take some process).\
\
**Example 3:** `TOTEXTDURATION(6067,24)` will return '**4d 5h 7m**' where each day has 24 hours (in this case you will get duration in full days).

</details>

<details>

<summary>FROMTEXTDURATION</summary>

Converts string in the `XXXh YYm` or `ZZZd XXh YYm` format to integer representing number of minutes. Returns numeric value.

**Usage:**

{% code overflow="wrap" %}

```apex
FROMTEXTDURATION(string_parameter, hours_in_day_optional) 
```

{% endcode %}

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`string_parameter`</mark>* *<mark style="color:cyan;">with a string to be converted.</mark>*

*<mark style="color:cyan;">Add optional</mark>* *<mark style="color:cyan;">`hours_in_day_optional`</mark>* *<mark style="color:cyan;">argument to specify how many work hours one working day consists of.</mark>*

**Example 1:** `FROMTEXTDURATION('62h 34m')` returns **3754** (62\*60 + 34).\
\
**Example 2:** `FROMTEXTDURATION('3d 2h 34m')` returns **4474** (3\*24\*60 +2\*60 + 34).\
\
**Example 3:** `FROMTEXTDURATION('3d 2h 34m',8)` returns **1594** (3\*8\*60 +2\*60 + 34).

</details>

<details>

<summary>MATCH</summary>

Searches a string for a match against a regular expression, and returns the matches in an array.

**Usage:**

{% code overflow="wrap" %}

```apex
MATCH(regex_string, data_string)
```

{% endcode %}

*<mark style="color:cyan;">Replace:</mark>*

* *<mark style="color:cyan;">`regex_string`</mark>* *<mark style="color:cyan;">with a regular expression</mark>*
* *<mark style="color:cyan;">`data_string`</mark>* *<mark style="color:cyan;">with the string to compare to regular expression</mark>*

**Example:**

<mark style="color:orange;">Let Duration\_\_c value is '8d'.</mark>

{% code overflow="wrap" %}

```apex
MATCH('[^abc]', {Stub__c.Duration__c}) 
```

{% endcode %}

Returns the following array: **(8, d)**.

</details>
