# Context

{% hint style="success" %}
This is the official documentation of Forest Admin Cloud.
{% endhint %}

The `context` of an action contains all the context data when the action is executed in Forest Admin.

***

{% hint style="info" %}
To make the code easier to read, all the code snippets below should be wrapped in the following code. Ensure you update the collection and action names as needed.

```typescript
import type { Agent } from '@forestadmin/forest-cloud';
import { Schema } from '../typings';

export default function customizeAgent(agent: Agent<Schema>) {
  agent.customizeCollection('user', (collection) => {
    collection.addAction('Ban user', {
      scope: 'Single',
      // Insert the code snippet here.
    });
  });
}
```

{% endhint %}

### Getting the selected record(s)

To get the selected record(s) on which the action is executed, use the `getRecord()` or `getRecords()` methods from the context.

Example:

{% tabs %}
{% tab title="Single scope" %}

```typescript
execute: async (context) => {
  const { id, email } = await context.getRecord(['id', 'email']);
},
```

{% endtab %}

{% tab title="Bulk or Global scopes" %}

```typescript
execute: async (context) => {
  const { id, email } = await context.getRecords(['id', 'email']);
},
```

{% endtab %}
{% endtabs %}

### Getting the selected record id(s)

Additionally, you can retrieve just the id(s) by using `getRecordId()` or `getRecordIds()`

Example:

{% tabs %}
{% tab title="Single scope" %}

```typescript
execute: async (context) => {
  const id = await context.getRecordId();
},
```

{% endtab %}

{% tab title="Bulk or Global scopes" %}

```typescript
execute: async (context) => {
  const ids = await context.getRecordIds();
},
```

{% endtab %}
{% endtabs %}

### Getting the collection

To access the collection associated with an action, use the `collection` attribute. To see the capabilities of what `collection` provides, please see the following section: [Query interface and Native Queries](https://docs.forestadmin.com/developer-guide-agents-nodejs/data-sources/getting-started/queries)

Example:

```typescript
execute: async (context) => {
  await context.collection.update(context.filter, { isBanned: true });
},
```
