# Process Document using AI

Process one or more documents with AI from Apex.

> Kind: Apex method · Updated: 2026-07-01

## Signature

```apex
global static void processDocument(
  List<Types.ProcessDocumentPayload> payloads,
  String runAs
)
```

### Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| payloads | List&lt;<a href="#/apex-type-process-document-payload">Types.ProcessDocumentPayload</a>&gt; | required | A list of Types.ProcessDocumentPayload, one entry per document to process. |
| runAs | String | required | Username to attribute the operation to; usually a static value such as 'integrationUser'. |

## Return Type

void — after CloudFiles finishes processing the document it fires the Document Processed platform event.

## Example

```apex
List<cldfs.Types.ProcessDocumentPayload> payloads = new List<cldfs.Types.ProcessDocumentPayload>{
  new cldfs.Types.ProcessDocumentPayload(
    'fileId',
    'driveId',
    'library',
    'context'
  )
};

cldfs.Client.processDocument(payloads,'integrationUser');
```

> **Testing** — Use ClientFactory with default mock values to get coverage without callouts. See How to get test coverage of code that uses Client methods.
