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

# Power Mode (SOQL Editor)

> Write custom SOQL queries for advanced file filtering and selection

## Overview

Power Mode gives you full control over file queries by allowing you to write custom SOQL (Salesforce Object Query Language) directly. This is ideal for advanced users who need complex filtering, custom field selection, or queries that go beyond what Simple Mode offers.

<Note>
  Power Mode requires SOQL knowledge. If you're new to SOQL, start with [Query Builder (Simple Mode)](/query-builder) or review our [SOQL Examples](/reference/soql-examples).
</Note>

## Enabling Power Mode

To switch to Power Mode:

1. Navigate to the **Query & Export** page
2. Find the **Power Mode** toggle in the query editor header
3. Click the toggle to enable Power Mode
4. The visual filters will be replaced with a Monaco code editor

<Info>
  Your Simple Mode filters will be converted to SOQL and pre-filled in the editor. You can then modify the query as needed.
</Info>

## The SOQL Editor

Power Mode features a Monaco editor (the same editor used in VS Code) with:

<CardGroup cols={2}>
  <Card title="Syntax Highlighting" icon="highlighter">
    SQL syntax highlighting for better readability
  </Card>

  <Card title="Line Numbers" icon="list-ol">
    Easily reference and debug specific lines
  </Card>

  <Card title="Multi-line Editing" icon="arrows-up-down">
    Write complex queries across multiple lines
  </Card>

  <Card title="Keyboard Shortcuts" icon="keyboard">
    Execute with `⌘/Ctrl + Enter`
  </Card>
</CardGroup>

### Editor Features

* **Dark Mode Support**: Automatically matches your system theme
* **Word Wrap**: Long queries wrap for better visibility
* **Tab Size**: 2 spaces for clean formatting
* **No Minimap**: Maximized editing space

## Supported SOQL Features

FileFetch supports standard SOQL syntax for querying Salesforce objects:

### SELECT Clause

Specify which fields to retrieve:

```sql theme={null}
SELECT Id, Title, ContentDocumentId, FileExtension, ContentSize
FROM ContentVersion
```

<Warning>
  FileFetch **requires** certain fields for file downloads to work:

  **For ContentVersion (Files)**:

  * `Id` - Record identifier
  * `ContentDocumentId` - Required for download

  **For Attachment**:

  * `Id` - Record identifier (also used for download)
</Warning>

### WHERE Clause

Filter results with conditions:

```sql theme={null}
SELECT Id, Title, ContentDocumentId
FROM ContentVersion
WHERE IsLatest = true
  AND CreatedDate = LAST_N_DAYS:30
  AND FileExtension IN ('pdf', 'docx')
  AND ContentSize > 1048576
```

**Supported Operators**:

* Comparison: `=`, `!=`, `<`, `>`, `<=`, `>=`
* Logical: `AND`, `OR`, `NOT`
* Pattern matching: `LIKE`
* List: `IN`, `NOT IN`
* Date literals: `LAST_N_DAYS:n`, `THIS_YEAR`, `LAST_YEAR`, etc.

### LIMIT Clause

Control the number of results:

```sql theme={null}
SELECT Id, Title, ContentDocumentId
FROM ContentVersion
WHERE IsLatest = true
LIMIT 500
```

<Tip>
  **Salesforce API Limits**: SOQL queries are limited to 2,000 rows per query. If you need more files, use [CSV Import](/csv-import) or run multiple queries with different filters.
</Tip>

### ORDER BY Clause

Sort results:

```sql theme={null}
SELECT Id, Title, CreatedDate
FROM ContentVersion
WHERE IsLatest = true
ORDER BY CreatedDate DESC
LIMIT 100
```

**Common Sorting**:

* `ORDER BY CreatedDate DESC` - Newest first
* `ORDER BY CreatedDate ASC` - Oldest first
* `ORDER BY Title ASC` - Alphabetical by name
* `ORDER BY ContentSize DESC` - Largest files first

## Object Filtering

Power Mode allows you to query files attached to specific objects using custom criteria.

<Warning>
  **Note**: The object filter dropdown is **disabled** in Power Mode. If you need to filter by related objects, you must write the query logic manually.
</Warning>

FileFetch uses a two-query approach when filtering by objects:

1. First query: Fetch record IDs from the target object (e.g., Account)
2. Second query: Fetch files linked to those records via ContentDocumentLink

**Example**: To find files on Accounts in California:

```sql theme={null}
-- This is conceptual - FileFetch handles the ContentDocumentLink join internally
-- You just specify the object filter criteria
```

For advanced object filtering, contact support or see [SOQL Examples](/reference/soql-examples).

## Common Query Patterns

### All PDFs Created This Year

```sql theme={null}
SELECT Id, Title, ContentDocumentId, FileExtension, ContentSize, CreatedDate
FROM ContentVersion
WHERE IsLatest = true
  AND FileExtension = 'pdf'
  AND CreatedDate = THIS_YEAR
ORDER BY CreatedDate DESC
LIMIT 500
```

### Large Files (> 10MB)

```sql theme={null}
SELECT Id, Title, ContentDocumentId, ContentSize, FileExtension
FROM ContentVersion
WHERE IsLatest = true
  AND ContentSize > 10485760
ORDER BY ContentSize DESC
LIMIT 200
```

### Files Modified in Last 7 Days

```sql theme={null}
SELECT Id, Title, ContentDocumentId, LastModifiedDate
FROM ContentVersion
WHERE IsLatest = true
  AND LastModifiedDate = LAST_N_DAYS:7
ORDER BY LastModifiedDate DESC
```

### Specific File Types

```sql theme={null}
SELECT Id, Title, ContentDocumentId, FileExtension
FROM ContentVersion
WHERE IsLatest = true
  AND FileExtension IN ('pdf', 'docx', 'xlsx', 'pptx')
LIMIT 1000
```

### Files with Specific Title Pattern

```sql theme={null}
SELECT Id, Title, ContentDocumentId, CreatedDate
FROM ContentVersion
WHERE IsLatest = true
  AND Title LIKE '%Invoice%'
ORDER BY CreatedDate DESC
LIMIT 500
```

### All Versions of Files

```sql theme={null}
SELECT Id, Title, ContentDocumentId, VersionNumber, CreatedDate
FROM ContentVersion
WHERE ContentDocumentId IN (
  SELECT ContentDocumentId
  FROM ContentVersion
  WHERE Title LIKE '%Contract%'
)
ORDER BY ContentDocumentId, VersionNumber
```

## Querying Attachments

For legacy attachments, query the Attachment object:

```sql theme={null}
SELECT Id, Name, ParentId, ContentType, BodyLength, CreatedDate
FROM Attachment
WHERE CreatedDate = LAST_N_DAYS:90
  AND Name LIKE '%.pdf'
ORDER BY CreatedDate DESC
LIMIT 500
```

**Key Differences from ContentVersion**:

* Use `Name` instead of `Title`
* Use `BodyLength` instead of `ContentSize`
* No `FileExtension` field (use pattern matching on `Name`)
* No version support (`IsLatest` not applicable)
* `ParentId` links directly to parent record

## Query Validation

FileFetch validates your query before execution:

<AccordionGroup>
  <Accordion title="✅ Valid Query">
    Query executes successfully and returns results in the table below the editor.
  </Accordion>

  <Accordion title="❌ Syntax Error">
    **Error**: `unexpected token: 'SELCT'`

    **Cause**: Typo or invalid SOQL syntax

    **Solution**: Review the query for typos and ensure proper SOQL syntax
  </Accordion>

  <Accordion title="❌ Invalid Field">
    **Error**: `No such column 'InvalidField' on entity 'ContentVersion'`

    **Cause**: Field doesn't exist on the object

    **Solution**: Check field API names in Salesforce or see [Salesforce Objects Reference](/reference/salesforce-objects)
  </Accordion>

  <Accordion title="❌ Missing Required Field">
    **Error**: Query must include `ContentDocumentId` for file downloads

    **Cause**: Required field not in SELECT clause

    **Solution**: Add the required field to your SELECT clause
  </Accordion>

  <Accordion title="⚠️ Too Many Results">
    **Warning**: Query returned 2000 rows (SOQL limit reached)

    **Cause**: Query matches more than 2000 records

    **Solution**: Add more specific WHERE conditions or use LIMIT
  </Accordion>
</AccordionGroup>

## Query History

FileFetch automatically saves your query history:

1. Click the **Query History** icon in the sidebar
2. View previously executed queries
3. Click a query to reload it in the editor
4. Edit and re-execute as needed

<Tip>
  Query history is saved locally and persists between sessions. Use this to quickly re-run common queries or learn from past searches.
</Tip>

## Help Text

While editing in Power Mode, you can access contextual help:

* Click the **?** icon or **Help** link
* View quick reference for SOQL syntax
* See examples of common WHERE clauses
* Access field reference for ContentVersion and Attachment

## Switching Back to Simple Mode

To return to visual filters:

1. Toggle **Power Mode** off
2. Your custom query will be **reset** to the default Simple Mode query
3. The visual filter dropdowns will reappear

<Warning>
  Switching back to Simple Mode **discards** your custom SOQL query. If you want to keep it, copy it first or save it in Query History.
</Warning>

## Best Practices

<CardGroup cols={2}>
  <Card title="Start Simple, Add Complexity" icon="layer-group">
    Begin with a basic query, then add filters incrementally
  </Card>

  <Card title="Test with LIMIT" icon="gauge">
    Use small LIMIT values while testing, then increase for full export
  </Card>

  <Card title="Use ORDER BY" icon="arrow-down-a-z">
    Sort results for predictable ordering and easier review
  </Card>

  <Card title="Comment Your Queries" icon="comment">
    Use `--` for comments to document complex query logic
  </Card>
</CardGroup>

## Limitations

Power Mode has some restrictions:

| Feature                 | Supported  | Notes                                      |
| ----------------------- | ---------- | ------------------------------------------ |
| **SELECT**              | ✅ Yes      | Must include required fields for downloads |
| **WHERE**               | ✅ Yes      | All standard SOQL operators                |
| **ORDER BY**            | ✅ Yes      | Single or multiple fields                  |
| **LIMIT**               | ✅ Yes      | Max 2000 (Salesforce limit)                |
| **OFFSET**              | ❌ No       | Not supported by FileFetch                 |
| **GROUP BY**            | ❌ No       | Not applicable for file exports            |
| **HAVING**              | ❌ No       | Not applicable for file exports            |
| **Subqueries**          | ⚠️ Limited | Only in WHERE clause, not FROM             |
| **Aggregate Functions** | ❌ No       | COUNT, SUM, etc. not supported             |
| **JOIN**                | ❌ No       | Use ContentDocumentLink filtering instead  |

## Advanced Examples

### Files Created by Specific User

```sql theme={null}
SELECT Id, Title, ContentDocumentId, CreatedBy.Name, CreatedDate
FROM ContentVersion
WHERE IsLatest = true
  AND CreatedBy.Name = 'John Smith'
ORDER BY CreatedDate DESC
```

### Files Larger Than Average

```sql theme={null}
-- First, calculate average size manually or use filters
SELECT Id, Title, ContentDocumentId, ContentSize
FROM ContentVersion
WHERE IsLatest = true
  AND ContentSize > 5242880  -- 5MB threshold
ORDER BY ContentSize DESC
LIMIT 100
```

### Files with Multiple Extensions

```sql theme={null}
SELECT Id, Title, ContentDocumentId, FileExtension
FROM ContentVersion
WHERE IsLatest = true
  AND (
    FileExtension LIKE 'doc%'
    OR FileExtension LIKE 'xls%'
    OR FileExtension LIKE 'ppt%'
  )
LIMIT 500
```

## Getting Help

<CardGroup cols={2}>
  <Card title="SOQL Examples" icon="book" href="/reference/soql-examples">
    Common query patterns and templates
  </Card>

  <Card title="Salesforce Objects" icon="database" href="/reference/salesforce-objects">
    Field reference for ContentVersion and Attachment
  </Card>

  <Card title="Troubleshooting" icon="wrench" href="/troubleshooting">
    Common query errors and solutions
  </Card>

  <Card title="Salesforce SOQL Guide" icon="external-link" href="https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/">
    Official Salesforce SOQL documentation
  </Card>
</CardGroup>
