> ## Documentation Index
> Fetch the complete documentation index at: https://developer.box.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Wiring the Box file picker to a custom invocable

Add the Box File Picker to your own Agentforce action so users pick a Box file in the action input instead of pasting file IDs. Two packaged pieces make it work:

* **`FileSelection`** — global Apex type with `selectedFileId` / `selectedFileName`. The value the picker returns.
* **`boxFileSelection`** — Lightning Type that renders the `boxFilePicker` UI (Recent Items / Browse Box Files / Current Record Folder).

Both ship in the package — you don't build them.

## Namespace (subscriber orgs)

Everything is under the `boxagents` namespace. In a subscriber org, reference packaged components with the prefix — the bare names won't compile:

| **Component** | **In a subscriber org** |
| - | - |
| Apex type | `boxagents.FileSelection` |
| Lightning Type | `boxagents__boxFileSelection` |

Using bare `FileSelection` causes *Invalid type: FileSelection* / *InvocableVariable fields do not support type ...* / *Variable does not exist: req.file*.

## Steps

1. Add a `boxagents.FileSelection` `@InvocableVariable` to your `Request`.
2. Read `req.file.selectedFileId` (and `selectedFileName`).
3. In Agent Builder, map that input to the `boxagents__boxFileSelection` Lightning Type so the picker UI renders.

Example

```
global with sharing class BoxFilePickerExample {
    @InvocableMethod(label='Get Selected Box File (Example)' description='Accept a file-picker selection and return the file ID' category='Box')
    global static List<Response> getSelectedFile(List<Request> requests) {
        List<Response> responses = new List<Response>();
        for(Request req : requests) {
            if(req.file == null || String.isBlank(req.file.selectedFileId)) {
                throw new IllegalArgumentException('File selection is required');
            }
            Response resp = new Response();
            resp.fileId = req.file.selectedFileId;
            resp.fileName = req.file.selectedFileName;
            responses.add(resp);
        }
        return responses;
    }
    global class Request {
        @InvocableVariable(label='Select File' description='Choose a Box file' required=true)
         global boxagents.FileSelection file;
    }    
    global class Response {
        @InvocableVariable(label='File ID') global String fileId;
        @InvocableVariable(label='File Name') global String fileName;
    }
}
```

## Mapping the input in Agent assets

![Mapping input agent assets](https://mintcdn.com/box/cWlL7gzZ3cIKeA5H/images/guides/tooling/salesforce-toolkit/mapping-input-agent-assets.png?fit=max\&auto=format\&n=cWlL7gzZ3cIKeA5H\&q=85\&s=e6515991b4e890b911ae4e5e4e7199df)

The Apex input lets the action *accept* a selection; mapping it to the Lightning Type makes the *picker UI render*:

1. Open your custom action (Agentforce Studio → Agent Actions, or Flow Builder).
2. Select the **Select File** input.
3. Set its reference / Lightning Type to **`boxagents__boxFileSelection`** (*Box File Picker*).
4. Save and activate.

## Notes

* Namespace prefix in subscriber orgs is the #1 source of errors.
* Null-check `req.file` / `req.file.selectedFileId`.
* The ID is what Box APIs need; the name is for display/logging.
* Full references: the shipped `BoxAIAskWithFilePicker`, `BoxAIGenTextWithFilePicker`, `BoxAIExtractFieldsWithFilePicker`, `BoxAIExtractMetadataWithFilePicker`.

**RELATED GUIDES**
