# System

## 1. COLUMNTOTAL

Calculates total quantities of records or evaluates total amounts / minimal values / maximal values / averages of values in the specified or current column considering column conditions and filters applied.

{% tabs %}
{% tab title="Usage" %}
`COLUMNTOTAL(column_id_optional, filter_optional, aggregation_type_optional, aggregation_field_optional)`.&#x20;

{% hint style="info" %}
All function parameters are optional and can be omitted (if last) or should be replaced with *null* (if not needed, but some arguments are to be placed after them).&#x20;
{% endhint %}

Parameters:

* `column_id_optional` - if leave empty or set to `null`, will calculate desired values for current column. If specify column ID, will calculate result for that column (this argument is necessary if column is unknown in current context, e.g., when function is executed on some cell in the Kanban header).
* `filter_optional` - if specify, will add custom filter string to query and calculate result matching this filter.
* `aggregation_type_optional` - if leave empty or set to `null`, will calculate total quantity of records matching the query, otherwise will calculate values with the way specified by proper aggregate function (see table below for a list and a [SOQL syntax](https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_agg_functions.htm) web reference for more help).
* `aggregation_field_optional` - API name of the field, should be specified when using aggregation types because of different aggregation functions support only fields of specific types.

List of aggregation types:

<table><thead><tr><th width="124">Aggregation function</th><th>Returned result</th><th width="170">Ignores null values?</th><th>Supported field types</th></tr></thead><tbody><tr><td><strong>COUNT</strong></td><td>Number of records matching the query criteria <em>(actually the same result as for empty or null proper argument)</em>.</td><td>No (if aggregation field is ID or is not specified) Yes (if other aggregation field is specified)</td><td>Any</td></tr><tr><td><strong>COUNT_DISTINCT</strong></td><td>Number of distinct non-null field values matching the query criteria.</td><td>Yes</td><td>Any</td></tr><tr><td><strong>AVG</strong></td><td>Average value of a numeric field.</td><td>Yes</td><td>Numeric</td></tr><tr><td><strong>SUM</strong></td><td>Total sum of a numeric field.</td><td>Yes</td><td>Numeric</td></tr><tr><td><strong>MIN</strong></td><td>Minimum value of a field.</td><td>Yes</td><td>Any. If use on a picklist field, the function uses the sort order of the picklist values instead of alphabetical order.</td></tr><tr><td><strong>MAX</strong></td><td>Maximum value of a field.</td><td>Yes</td><td>Any. If use on a picklist field, the function uses the sort order of the picklist values instead of alphabetical order.</td></tr></tbody></table>
{% endtab %}

{% tab title="Example 1" %}
`COLUMNTOTAL()` returns a total number of records in the current column.
{% endtab %}

{% tab title="Example 2" %}
`COLUMNTOTAL({$Variables.myColumnId}, 'Type = {QUOTE}Electrical{QUOTE}')` will return total number of records that match custom filter **Type='Electrical'** and belong to column with ID stored in variable "*myColumnId*".
{% endtab %}

{% tab title="Example 3" %}
Let Priority = picklist with these values: **'High', 'Medium', 'Low', 'No priority'**.

`COLUMNTOTAL(null, null, 'MAX', 'Priority')` returnы '**No priority**' because it is the latest value in picklist field.
{% endtab %}

{% tab title="Example 4" %}
`COLUMNTOTAL(null, null, 'MIN', 'Units')` returns the minimal number value if the field is numeric, and first alphabetically sorted value if the field is text.
{% endtab %}

{% tab title="Example 5" %}
`COLUMNTOTAL({$Variables.myColumnId}, 'Stage = {QUOTE}Closed Won{QUOTE}', 'AVG', 'ExpectedRevenue__с')` returns average *Expected Revenue* amount for opportunities in *Closed Won* stage.
{% endtab %}
{% endtabs %}

## 2. BUILDFORMLINK

Builds a web URL to specified Form.

{% tabs %}
{% tab title="Usage" %}
`BUILDFORMLINK(form_id, record_id, mode, context_fields, parameters, entire_height, as_html_tag_optional, text_optional)`

Parameters:

* `form_id`  - ID of form to be linked to
* `record_id` - ID of record to be used as data source
* `mode` - form mode (edit, view or new)
* `context_fields` - JSON with the list of virtual fields and their values (for pre-population)
* `parameters` - JSON with parameters that will be passed to the form
* `entire_height` - **true** or **false**. If set to **true**, form will take all available height of container, even if no such space required to show form elements
* `as_html_tag_optional` - optional argument. If set to **true**, not only form URL will be generated, but HTML tag `<a>` with `href` attribute equal to this URL
* `text_optional` - optional argument. If set to any text except null, this text will be placed as inner content of `<a>` tag (has sense only if `as_html_tag_optional` is set to **true**)

{% hint style="info" %}
Note: if omit `record_id` argument, form will be shown without object fields populated. If the form mode is "edit", it will be the same result as for "new" mode.
{% endhint %}
{% endtab %}

{% tab title="Example 1" %}
Let your application is located at **your-app-url.com** address.

`BUILDFORMLINK('a0C9m00000T4LvWDFC', '5001A00000SdeRqQFF', 'edit')` returns the following URL:&#x20;

```
https://your-app-url.com/lightning/cmp/c__FormPanel?c__entireHeight=false&c__formId=a0C9m00000T4LvWDFC&c__mode=edit&c__recordId=5001A00000SdeRqQFF
```

{% endtab %}

{% tab title="Example 2" %}
Let your application is located at **your-app-url.com** address.

`BUILDFORMLINK('a0C9m00000T4LvWDFC','5001A00000SdeRqQFF','edit', null,'{"aaa":"bbb"}',false,true)` returns the following HTML code:&#x20;

```
<a href="https://your-app-url.com/lightning/cmp/c__FormPanel?c__entireHeight=false&c__formId=a0C9m00000T4LvWDFC&c__mode=edit&c__parameters=%7B%22aaa%22%3A%22bbb%22%7D&c__recordId=5001A00000SdeRqQFF">https://your-app-url.com/lightning/cmp/c__FormPanel?c__entireHeight=false&c__formId=a0C9m00000T4LvWDFC&c__mode=edit&c__parameters=%7B%22aaa%22%3A%22bbb%22%7D&c__recordId=5001A00000SdeRqQFF</a>
```

{% endtab %}

{% tab title="Example 3" %}
Let your application is located at **your-app-url.com** address.

`BUILDFORMLINK('a0C9m00000T4LvWDFC','5001A00000SdeRqQFF','edit', '{"inputTextarea":"This is some description"}', null, false, true, 'My Link Text')` returns the following HTML code:&#x20;

```
<a href="https://your-app-url.com/lightning/cmp/c__FormPanel?c__contextFields=%7B%22inputTextarea%22%3A%22This+is+some+description%22%7Dc__entireHeight=false&c__formId=a0C9m00000T4LvWDFC&c__mode=edit&c__recordId=5001A00000SdeRqQFF">My Link Text</a>
```

{% endtab %}
{% endtabs %}

## 3. BUILDDASHBOARDLINK

Builds a web URL to specified Kanban.

{% tabs %}
{% tab title="Usage" %}
`BUILDDASHBOARDLINK(dashboard_id, variables, styles, as_html_tag_optional, text_optional)`

Parameters:

* `dashboard_id`  - ID of dashboard (kanban) to be linked to
* `variables` - JSON with the list of variables to be passed to dashboard. This argument is mandatory, so, replace it with `null` if no variables needed.
* `styles` - string with CSS properties to be passed to dashboard. This argument is mandatory, so, replace it with `null` if no styles needed.

{% hint style="warning" %}
Note: `styles` argument is actually passed as URL parameter, but does not supported by Kanban page (reserved for future use).
{% endhint %}

* `as_html_tag_optional` - optional argument. If set to **true**, not only dashboard URL will be generated, but HTML tag `<a>` with `href` attribute equal to this URL.
* `text_optional` - optional argument. If set to any text except null, this text will be placed as inner content of `<a>` tag (has sense only if `as_html_tag_optional` is set to **true**)
  {% endtab %}

{% tab title="Example 1" %}
Let your application is located at **your-app-url.com** address.

`BUILDDASHBOARDLINK('a003m00002CvxffAAB','{"myVariable_1":"Some text"}',null)` returns the following URL:

```
https://your-app-url.com/lightning/cmp/c__KanBanComponent?c__kanbanId=a003m00002CvxffAAB&c__variables=%7B%22myVariable_1%22%3A%22Some+text%22%7D
```

{% endtab %}

{% tab title="Example 2" %}
`BUILDDASHBOARDLINK('a003m00002CvxffAAB',null,null,true)` returns the following HTML code:

```
<a href="https://your-app-url.com/lightning/cmp/c__KanBanComponent?c__kanbanId=a003m00002CvxffAAB">https://your-app-url.com/lightning/cmp/c__KanBanComponent?c__kanbanId=a003m00002CvxffAAB</a>
```

{% endtab %}

{% tab title="Example 3" %}
`BUILDDASHBOARDLINK('a003m00002CvxffAAB','{"myVariable_1":"Some text"}',null,true,'My Dashboard')` returns the following HTML code:

```
<a href="https://your-app-url.com/lightning/cmp/c__KanBanComponent?c__kanbanId=a003m00002CvxffAAB&c__variables=%7B%22myVariable_1%22%3A%22Some+text%22%7D">My Dashboard</a>
```

{% endtab %}
{% endtabs %}

## 4. CHECKPERMISSION

Returns **true** if current user has listed permissions (all or at least one) or **false** if not.

{% tabs %}
{% tab title="Usage" %}
`CHECKPERMISSION(name_or_names_json_array, atleastone_boolean_optional)`

Parameters:

* `name_or_names_json_array`  - name of the permission to be checked or JSON array of permission names.
* `atleastone_boolean_optional` - if set to `true`, function will return **true** if current user has at least one permission from the array in first agrument, otherwise (or if omitted) function will return **true** only if current user has all listed permissions.
  {% endtab %}

{% tab title="Example 1" %}
Let your user has these permissions: **User\_Test\_Permission, Process\_admin**.

`CHECKPERMISSION('User_Test_Permission')` returnы **true** if current user has this permission.
{% endtab %}

{% tab title="Example 2" %}
`CHECKPERMISSION(SPLIT('User_Test_Permission,Process_admin', ','))` returns **true** if current user has both these permissions.
{% endtab %}

{% tab title="Example 3" %}
`CHECKPERMISSION(SPLIT('User_Test_Permission,Process_admin', ','),false)` returns **true** if current user has both these permissions.
{% endtab %}

{% tab title="Example 4" %}
`CHECKPERMISSION(SPLIT('User_Test_Permission,Process_admin', ','),true)` returns **true** if current user has at least one of these permissions.
{% endtab %}
{% endtabs %}

## 5. USERIN

Returns **true** if given user belongs to at least one of listed users, roles, profiles, queues or groups.

{% tabs %}
{% tab title="Usage" %}
`USERIN(user_id, users_roles_profiles_groups_ids)`.

Parameters:

* `user_id`  - ID of user which is being checked.
* `users_roles_profiles_groups_ids` - one ID or list of IDs of of users/roles/profile/group/queue.
  {% endtab %}

{% tab title="Example" %}
`USERIN({$User.id}, 0083n000008qatjCVV)` returns **true** if current user ID is equal to second parameter.
{% endtab %}

{% tab title="Example 2" %}
`USERIN({$User.id}, ('0083n000008qatjCVV,00G3m000003pllF'))` returns **true** if current user ID is in the listed IDs.
{% endtab %}
{% endtabs %}
