# Text

## 1. SPECIALSYMBOLS

Allows using of special symbols within the formula.

{% tabs %}
{% tab title="Usage" %}
Use any of the below expressions whenever you need formula to contain special symbol(s):

`{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 (`\`)\
`{BR}` for line break\
`{RET}` for carriage return
{% endtab %}

{% tab title="Example" %}
`IF(STARTS({Request__c.Name}, 'RFQ'), '{OPEN_SQR_BKT}Request for Quote{CLOSE_SQR_BKT}', '{OPEN_SQR_BKT}Service{CLOSE_SQR_BKT}')` will return **\[Request for Quote]** if request name starts with 'RFQ', and **\[Service]** if it doesn't.
{% endtab %}
{% endtabs %}

## 2. CONTAINS

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

{% tabs %}
{% tab title="Usage" %}
`CONTAINS(source_string, search_string)`&#x20;

Replace `source_string` with the text that should be searched for a value of `search_string`.
{% endtab %}

{% tab title="Example" %}
`IF(CONTAINS({Opportunity.Product_Type__c}, 'part'), 'Parts', 'Service')` - this formula checks the content of a text field named *Product\_Type\_\_c* and returns '**Parts**' for any product with the word 'part' in it. Otherwise, it returns '**Service**'.
{% endtab %}
{% endtabs %}

## 3. STARTS

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

{% tabs %}
{% tab title="Usage" %}
`STARTS(source_string, search_string)`

Replace `source_string` with the text that should be checked for starting from the value of `search_string`.
{% endtab %}

{% tab title="Example" %}
`IF(STARTS({Request__c.Name}, 'RFQ'), 'Request for Quote', 'Service')` - this formula checks the content of a *Name*  field and returns '**Request for Quote**' for any request name starting with 'RFQ'. Otherwise, it returns '**Service**'.
{% endtab %}
{% endtabs %}

## 4. POS

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

{% tabs %}
{% tab title="Usage" %}
`POS(source_string, search_string)`

Replace `source_string` with the field or expression you want to search and `search_string` with the string you want to find.
{% endtab %}

{% tab title="Example" %}
`POS({Contact.Email}, '@')` returns the location of the `@` sign in a person's email address.
{% endtab %}
{% endtabs %}

## 5. ENDS

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

{% tabs %}
{% tab title="Usage" %}
`ENDS(source_string, search_string)`&#x20;

Replace `source_string` with the text that should be checked for ending with the value of `search_string`.
{% endtab %}

{% tab title="Example" %}
`IF(ENDS({Company__c.Name}, 'TM'), 'Trademark', 'Service mark')` this formula checks the content of a *Name* field and returns '**Trademark**' for any item ending with 'TM'. Otherwise, it returns '**Service mark**'.
{% endtab %}
{% endtabs %}

## 6. SUBSTR

Returns a new String that begins with the character at the specified start position and extends until the character at end position.

{% tabs %}
{% tab title="Usage" %}
`SUBSTR(source_string, start_index, end_index)`&#x20;

Replace `source_string` with the  string, field or expression where you want to get a substring from, `start_index` with the position substring begins from, `end_index` with the position substring ends at.

{% hint style="warning" %}
Note that position indexes are starting from 0.
{% endhint %}
{% endtab %}

{% tab title="Example" %}
`SUBSTR({Contact.Name}, 4, 8)` in case when *Contact.Name* value = '*Jefferson*' function will return '**erso**'.
{% endtab %}
{% endtabs %}

## 7. REPLACE

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

{% tabs %}
{% tab title="Usage" %}
`REPLACE(source_string, from_string, to_string, regex_boolean_optional)`

Replace `source_string` with string to be changed, `from_string` with characters to be replaced in `source_string`, and `to_string` with the replacement set of characters.

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.
{% endtab %}

{% tab title="Example 1" %}
`REPLACE({Opportunity.Unique_ID__c}, '3a', '2b')` - the *Unique\_ID\_\_c* will now contain new value with the '`3a`' replaced with '`2b`'.
{% endtab %}

{% tab title="Example 2" %}
`REPLACE('a3f45qq456', '[^0-9]', '', true)` will return **345456**.
{% endtab %}
{% endtabs %}

## 8. Remove

Removes one or more substrings from a source string.

{% tabs %}
{% tab title="Usage" %}
`REMOVE(source_string, string_parameter1, string_parameter2, ...)`&#x20;

Replace `source_strin`g with the text field or expression you want to remove substrings from and `string_parameter1`, `string_parameter2`,  etc with substrings to be removed from the source string.
{% endtab %}

{% tab title="Example" %}
`REMOVE('(555) 555-6789 ', ' ', '(', ')', '-')` will return '**5555556789**'.
{% endtab %}
{% endtabs %}

## 9. LEN

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

{% tabs %}
{% tab title="Usage" %}
`LEN(string)`&#x20;

Replace `string` with the field or expression which length you want get.
{% endtab %}

{% tab title="Example" %}
`LEN({Product__с.Code__c})` returns the length of a *Product.Code* field.
{% endtab %}
{% endtabs %}

## 10. SPLIT

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

{% tabs %}
{% tab title="Usage" %}
`SPLIT(source_string, separator_string)`&#x20;

Replace `source_string` with the text field or expression to be split, and `separator_string`  with a substring to split on.
{% endtab %}

{% tab title="Example" %}
`SPLIT('AL, AK, AZ, AR', ', ')` will return an array of string type elements.
{% endtab %}
{% endtabs %}

## 11. JOIN

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

{% tabs %}
{% tab title="Usage" %}
`JOIN(array, separator_string, left_string_optional, right_string_optional)`&#x20;

Replace `array` argument with an array you want to join to a string, `separator_string` with a string to insert between array elements. `left_string_optiona`l and `right_string_optional` arguments are optional and can be used to modify array elements (add some text leftside or rightside of each of them) before joining.
{% endtab %}

{% tab title="Example" %}
Let *String\_\_c* field on *Stub\_\_c* object stores following string: '**Cars, Plains, Ships**'.

`{OPEN_SQR_BKT} + JOIN(SPLIT({Stub__c.String__c}, ','), ',', '{DBL_QUOTE}', '{DBL_QUOTE}') + {CLOSE_SQR_BKT}` - this formula will split field value to an array and then transform it to a following string: '**\["Cars", "Plains", "Ships"]**'.
{% endtab %}
{% endtabs %}

## 12. LOWER

Converts all of the characters in the string to lowercase.

{% tabs %}
{% tab title="Usage" %}
`LOWER(string)`&#x20;

Replace `string` parameter with a string you need to convert to lowercase.
{% endtab %}

{% tab title="Example" %}
`LOWER({Account.Name})` will return *Account Name* value in lowercase.
{% endtab %}
{% endtabs %}

## 13. UPPER

Converts all of the characters in the string to uppercase.

{% tabs %}
{% tab title="Usage" %}
`UPPER(string)`

Replace `string` parameter with a string you need to convert to uppercase.
{% endtab %}

{% tab title="Example" %}
`UPPER({Account.Name})` will return *Account Name* value in uppercase.
{% endtab %}
{% endtabs %}

## 14. ESCAPE

Returns a string which characters are escaped using specified rule.

{% tabs %}
{% tab title="Usage" %}
`ESCAPE(string, JAVA|JSON|HTML|CSV|XML|UNICODE|QUOTE)`&#x20;

Replace `string` parameter with a sting to be escaped and sepcify one of the allowed escape rules as second argument.
{% endtab %}

{% tab title="Example" %}
Let *Error\_\_c* value is '**Please, fill in "Name"**'.\
`ESCAPE({Stub__c.Error__c}, 'HTML')` will return '**Please, fill in \&quot;Name\&quot;**'\
`ESCAPE({Stub__c.Error__c}, 'JAVA')` will return '**Please, fill in \\"Name\\**"'\
`ESCAPE({Stub__c.Error__c}, 'CSV')` will return '**"Please, fill in ""Name"""**'\
`ESCAPE({Stub__c.Error__c}, 'XML')` will return '**Please, fill in \&quot;Name\&quot;**'

Let *String\_\_c* value is '**De onde você é?**'\
`ESCAPE({Stub__c.String__c}, 'UNICODE')` will return '**De onde voc\u00EA \u00E9?**'
{% endtab %}
{% endtabs %}

## 15. ID

Converts a string to Salesforce object ID.

{% tabs %}
{% tab title="Usage" %}
`ID(string)`&#x20;

Replace `string` argument with value that should be treated as ID.
{% endtab %}

{% tab title="Example" %}
I`D('a006m00007sMGHjAAO')` will return **a006m00007sMGHjAAO** (some object ID).
{% endtab %}
{% endtabs %}

## 16. BR

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

{% tabs %}
{% tab title="Usage" %}
Add `BR()` to other functions or output text values wherever you need a line break.
{% endtab %}

{% tab title="Example" %}
`JOIN(SPLIT({Account.Account_Multy__c}, ';'), BR())` - this formula will first split field value to an array and then transform it to a following text:

```
'A
B
C'
```

{% endtab %}
{% endtabs %}

## 17. TEXT

Converts any data type into text.

{% tabs %}
{% tab title="Usage" %}
`TEXT(parameter)`&#x20;

Replace `parameter` with the field or expression you want to convert to text format.
{% endtab %}

{% tab title="Example" %}
`IF(TEXT({Stub__c.Number__c}) = {Stub__c.Text__c}, true, false)`  will return **true** when given *Stub.Number* numeric value is 25 and *Stub.Text* string value is '25'.

{% hint style="info" %}
You can't directly compare values of different types, so, such conversion may be very useful.
{% endhint %}
{% endtab %}
{% endtabs %}

## 18. BLOB

Casts the specified string to a Binary Large Object.

{% tabs %}
{% tab title="Usage" %}
`BLOB(string)`&#x20;

Replace `string` argument with a string you need to cast to BLOB
{% endtab %}

{% tab title="Example" %}
`BLOB({Account.LongTextField__c})` will return field value as the BLOB content.
{% endtab %}
{% endtabs %}

## 19. TOBASE64

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

{% tabs %}
{% tab title="Usage" %}
`TOBASE64(blob_parameter)`&#x20;

Replace `blob_parameter` with a BLOB content you need to convert to base64.
{% endtab %}

{% tab title="Example" %}
Let *Account.Name* value is '**Mary Ann'**.

`TOBASE64(BLOB({$Account.Name}))` will return '**TWFyeSBBbm4=**'&#x20;
{% endtab %}
{% endtabs %}

## 20. FROMBASE64

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

{% tabs %}
{% tab title="Usage" %}
`FROMBASE64(string_parameter)`&#x20;

Replace `string_parater` with Base64-encoded string.
{% endtab %}

{% tab title="Example" %}
`FROMBASE64('TWFyeSBBbm4=')` will return BLOB content of a '**Mary Ann**' string.
{% endtab %}
{% endtabs %}

## 21. TOHEX

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

{% tabs %}
{% tab title="Usage" %}
`TOHEX(string_parameter)`&#x20;

Replace `string_parameter` with a string you need to convert to hex.
{% endtab %}

{% tab title="Example" %}
Let *Account.Name* value is '**Mary Ann'**.

`TOHEX({Account.Name})` will return '**4d61727920416e6e**'.
{% endtab %}
{% endtabs %}

## 22. FROMHEX

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

{% tabs %}
{% tab title="Usage" %}
`FROMHEX(string_parameter)`&#x20;

Replace `string_parameter` with a hex string you need to convert to text.
{% endtab %}

{% tab title="Example" %}
`FROMHEX('4d61727920416e6e')` will return '**Mary Ann**' string.
{% endtab %}
{% endtabs %}

## 23. URLENCODE

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

{% tabs %}
{% tab title="Usage" %}
`URLENCODE(string_to_encode, format_optional, boolean_encode_optional)`&#x20;

Replace `string_to_encode` parameter with string to be encoded (or decoded).

Optionally: provide specific encoding scheme in `format_optional` argument (default is **UTF-8**), and pass *false* as a `boolean_encode_optional` argument if you need to decode string.
{% endtab %}

{% tab title="Example 1" %}
Let *String\_\_c* value is '**Test / me**'.

`URLENCODE({Stub__c.String__c})` will return '**Test+%2F+me**'.&#x20;
{% endtab %}

{% tab title="Example 2" %}
Let *String\_\_c* value is '**Test+%2F+me**'.

`URLENCODE({Stub__c.String__c}, 'UTF-8', false)` will return '**Test / me**'.
{% endtab %}
{% endtabs %}

## 24. TOTEXTDURATION

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

{% tabs %}
{% tab title="Usage" %}
`TOTEXTDURATION(integer_minutes_parameter, hours_in_day_optional)`&#x20;

Replace `integer_minutes_parameter` with integer representing number of minutes to get duration in hours and minutes.&#x20;

Optional `hours_in_day_optional` argument represents how many hours in a working day are set. Add it to get duration in working days, hours and minutes.
{% endtab %}

{% tab title="Example 1" %}
`TOTEXTDURATION(6067)` will return '**101h 7m'**.
{% endtab %}

{% tab title="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).
{% endtab %}

{% tab title="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).
{% endtab %}
{% endtabs %}

## 25. FROMTEXTDURATION

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

{% tabs %}
{% tab title="Usage" %}
`FROMTEXTDURATION(string_parameter, hours_in_day_optional)`&#x20;

Replace `string_parameter` with a string to be converted.&#x20;

Add optional `hours_in_day_optional` argument to specify how many work hours one working day consists of.
{% endtab %}

{% tab title="Example 1" %}
`FROMTEXTDURATION('62h 34m')` will return **3754** (62\*60 + 34).
{% endtab %}

{% tab title="Example 2" %}
`FROMTEXTDURATION('3d 2h 34m')` will return **4474** (3\*2&#x34;*\**&#x36;0 + 2\*60 + 34).
{% endtab %}

{% tab title="Example 3" %}
`FROMTEXTDURATION('3d 2h 34m',8)` will return **1594** (3\*&#x38;*\**&#x36;0 + 2\*60 + 34).
{% endtab %}
{% endtabs %}

## 26. MATCH

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

{% tabs %}
{% tab title="Usage" %}
`MATCH(regex_string, data_string)`

Replace `regex_string` with a regular expression, and `data_string` with the string to compare to regex.
{% endtab %}

{% tab title="Example" %}
Let *Duration\_\_c* value is '**8d**'.&#x20;

`MATCH('[^abc]', {Stub__c.Duration__c})` will return following array: **(8, d)**.
{% endtab %}
{% endtabs %}
