---
title: Delete documents for a batch
summary: Removes every document belonging to a print-control batch once the batch has finished printing.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-07-30
library: SAIF.Services.Printing.Remote
reference_type: package
operation_id: OP-006
trigger: A caller invokes the delete lifecycle on a clsXDocumentCollection instance with XPrintControlSeqNum set, typically after a batch has finished printing
---

# Delete documents for a batch

This operation bulk-removes all documents associated with a print-control batch, used for cleanup once the batch has been printed. It operates at the collection level and has no per-document counterpart — individual documents are never deleted on their own in this library.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-006 |
| **Trigger** | Caller invokes the delete lifecycle on a `clsXDocumentCollection` instance with `XPrintControlSeqNum` set |
| **Inputs** | `XPrintControlSeqNum` |
| **Outputs** | Rows removed from `XDOCUMENT`; error message on row-count contention |
| **Primary components** | `clsXDocumentCollection.AfterDelete`, `clsXDocumentCollection.Criteria.DeleteSQL` |
| **Entry point** | `Services\SAIF.Services.Printing.Remote\clsXDocumentCollection.vb` |

## Steps

1. **Invoke the delete.** Caller triggers the delete lifecycle on a `clsXDocumentCollection` instance whose `XPrintControlSeqNum` identifies the batch to clear.
2. **Execute the delete.** `Criteria.DeleteSQL` defines [SQL-021](../sql/SQL-021-saif-services-printing-remote.md) (`DELETE XDOCUMENT WHERE XPRINT_CONTROL_SEQ_NUM = :XPrintControlSeqNum`, [XDOCUMENT](../database-tables.md#xdocument)).
   - No `BeforeDelete` override exists in `clsXDocumentCollection` in this library's source — the request's construction and parameter binding for this delete depend on undocumented base-class (`clsBusinessCollectionBase`) default wiring that could not be verified from this library's own code.**
3. **Check the outcome.** `AfterDelete` reads the rows-affected result and checks `RowsAffected <> 1`, adding `DeleteError` ("Delete Failed") when the check fails ([BR-001](../business-rules.md#br-001-row-count-contention-check)).
   - Note: for a batch with more than one document, deleting "all documents for a batch" will affect more than one row by design, yet the check only tolerates exactly `1`; whether this check is meaningful for a genuinely multi-document batch (versus always firing as a false-positive contention error) could not be confirmed from source.**

## Process flow

The following diagram visualizes the batch document cleanup.

```mermaid
flowchart TD
	Start([Caller triggers delete on<br>clsXDocumentCollection with XPrintControlSeqNum]) --> Exec[Execute DELETE XDOCUMENT<br>WHERE XPrintControlSeqNum = value]
	Exec --> Check{RowsAffected = 1?}
	Check -->|No| Err([DeleteError added —<br>fires for 0 or 2+ rows alike])
	Check -->|Yes| Ok([Documents removed])
```

## Failure and edge-case behavior

- No `BeforeDelete` override is present for `clsXDocumentCollection`, so the exact request construction and parameter binding for this delete cannot be confirmed from this library's own source — it relies on base-class default behavior.**
- The `AfterDelete` contention check tests for exactly one row affected, which does not naturally accommodate deleting a genuinely multi-document batch; its practical behavior for batches with more than one document is unconfirmed.**
- This is the only way documents are removed in this library — there is no live delete path on the single-document `clsXDocument` class.

> **Note:** Statements marked with `**` could not be confirmed; treat as unknown until verified.

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)
- [SQL catalog](../sql/index.md)
- [Database tables](../database-tables.md)

## Sources
- `Services\SAIF.Services.Printing.Remote\clsXDocumentCollection.vb`
