# Create Dataset

Create a Document AI dataset from a set of files, from Apex.

> Kind: Apex method · Updated: 2026-10-05

## Signature

```apex
global static void createDataset(
  List<Types.CreateDatasetInput> datasetInputs,
  String runAs
)
```

### Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| datasetInputs | List&lt;<a href="#/apex-type-create-dataset-input">Types.CreateDatasetInput</a>&gt; | required | One entry per dataset to create. Each Types.CreateDatasetInput names the dataset and lists its files. |
| runAs | String | optional | Email Id of the user on whose behalf the function should run. To run the action as the automation user, supply integrationUser. |

## Return Type

void. The dataset is created in the background. When it is ready, CloudFiles publishes a Dataset Created event carrying the new dataset Id and your context. Query it with Query Document.

## Example

```apex
List<cldfs.Resource> files = new List<cldfs.Resource>{
  new cldfs.Resource('01KEHAKUXCQ6YIOFLOPJHJN57Y5EYQTJMZ', 'file', null, 'sharepoint', 'b!nJBtPq_z5UeJtFrj_f24XEQqlPUD8vtFsg7GBcrXJepiUn9bkb_7QbDPtqHVD-cP'),
  new cldfs.Resource('01KEHAKUQ4HW7VGNGBYVFJ3F2ZB2NNO5QX', 'file', null, 'sharepoint', 'b!nJBtPq_z5UeJtFrj_f24XEQqlPUD8vtFsg7GBcrXJepiUn9bkb_7QbDPtqHVD-cP')
};

List<cldfs.Types.CreateDatasetInput> inputs = new List<cldfs.Types.CreateDatasetInput>{
  new cldfs.Types.CreateDatasetInput(
    'Supplier contracts 2026', // name
    'Signed supplier contracts for this year', // description
    files,
    '006dL000005H4srQAC' // context, returned on the Dataset Created event
  )
};

cldfs.Client.createDataset(inputs, 'integrationUser');
```

> **Building on an existing dataset** — Pass the Id of an existing dataset as datasetId (the five-argument constructor) to create a new dataset that holds the existing dataset's sources plus the files you list. The existing dataset is not changed. If no dataset has that Id, the dataset is not created.
