20261026 - The Rollback That Wasn’t Transaction & Error Handling
AL transaction and error handling in Business Central: what rollback does and does not undo, why try functions do not undo writes online, how Commit and the CommitBehavior attribute work, and how to test and review transaction code. Includes patterns for external integration and batch processing.
- Introduction and Housekeeping
- Speaker Introduction and Session Overview
- Transaction Basics and ACID Properties
- Why Transaction Atomicity Matters
- Transaction Ownership and Commit Behavior
- What Rollback Actually Undoes and Posting Preview
- The Rollback That Wasn't - First Bug Pattern
- Ways to Prevent Rollback in Try Functions
- The Rollback You Didn't Want - Error Handling Patterns
- The Rollback That Can't Happen - External System Integration
- Transaction Control Tools and Commit Fundamentals
- Commit Anti-Patterns and Batch Checkpointing
- CommitBehavior Attribute and Integration Events
- CommitBehavior Rules and Scope
- Commit Behavior Applications: ignore vs error
- Scoped Undo Button: Error-scoped Code Units
- Code Unit Transactions: Common Mistakes
- Wrong Fixes and the Right Approach
- Try Functions: When to Use and Not Use
- Fixing Try Function Anti-patterns
- Test Transaction Models
- Testing rollback and transaction scenarios
- Error info data type and fix-it actions
- Collectible errors and error behavior collect
- Real-world examples: parallel worker and batch processing
- Decision map for transaction patterns
- Code review checklist for transactions and errors
- Key Principles and Best Practices Summary
- Q&A: Commit Behavior and Default Settings
- Q&A: Try-Catch Behavior in Cloud vs On-Premise
- Presentation Availability and Technical Discussion
- Closing Remarks and Upcoming Events
Overview
The session explains how the AL runtime manages database transactions. A write transaction starts on the first insert, modify or delete and commits when code ends without error. Rollback undoes only writes to normal tables since the last commit. Variables, temporary records, single instance codeunit state, HTTP calls, emails and telemetry are not undone. The speaker uses this to explain posting preview, which relies on temporary data surviving an intentional rollback.
The talk then covers the common failure patterns and the tools to avoid them. Try functions catch errors but do not undo writes; online allows writes in try methods, while on-premises blocks them by default. Explicit commits make earlier work final. CommitBehavior can ignore or error on commits in called code. Error-scoped codeunits used with a return value act as a scoped undo. The talk also covers test transaction models, ErrorInfo with fix-it actions, collectible errors, an outbox pattern for external systems, a batch checkpoint pattern, and an eight-item code review checklist.
Key points
- Rollback undoes inserts, modifies and deletes on normal tables since the last commit. It does not undo variables, temporary records, single instance codeunit state, HTTP calls, sent emails or telemetry.
- Posting preview uses this on purpose: it posts into real tables while subscribers copy entries into temporary tables, then raises an intentional error caught by if Codeunit.Run. The real posting rolls back but the temporary copies survive.
- A try function catches the error but does not undo writes made inside it. Online allows writes in try methods; on-premises blocks them by default (an NST setting that can be changed on-premises but not online). The documentation says this behavior might change in an upcoming release.
- A try function only forms a boundary when its return value is used. A bare call is an ordinary call and the error propagates.
- Commit makes everything since the last commit final, including callers’ and subscribers’ writes. Each commit should have a comment saying why, and the state after it must be recoverable.
- CommitBehavior on a procedure or event can ignore commits or raise an error on them. The stricter rule wins in parent-child combinations, and the attribute cannot be conditional. In BC 29, Sales-Post runs line posting under CommitBehavior Ignore by default, and posting preview uses Error.
- Running a codeunit with its Boolean return value (if Codeunit.Run) works as a scoped undo, but only from a clean state. Commit first if a write transaction is open; the runtime enforces this, the compiler does not.
Features
| Feature | Status | At | Evidence |
|---|---|---|---|
| Transaction control in AL runtime | status not stated | 6:37 | |
| Rollback scope limitations | status not stated | 10:42 | |
| Explicit commit splitting transactions | status not stated | 9:59 | |
| The rollback that wasn’t - try-catch with database writes | status not stated, demoed | 13:20 | |
| Try function error handling | status not stated, demoed | 13:10 | |
| Commit method behavior | status not stated, demoed | 19:41 | |
| Outbox pattern for external integration | status not stated | 17:26 | |
| Idempotent request IDs | status not stated | 17:57 | |
| External Business Events post-commit behavior | status not stated | 18:23 | |
| Batch checkpoint pattern | status not stated, demoed | 22:07 | |
| Commit Behavior function attribute | generally available, demoed | 26:31 | “Microsoft ships this in base app. Sales post runs the posting lines under commit behavior ignore by default, at least in BC 29.” (27:54) |
| Error-scoped Code Units for clean state transactions | status not stated, demoed | 29:35 | |
| Try function attribute with return value | status not stated, demoed | 36:13 | |
| Test transaction models | status not stated | 40:04 | |
| Test transaction model - after rollback | status not stated, demoed | 40:15 | |
| Test transaction model - after commit | status not stated, demoed | 40:37 | |
| Test transaction model - none | status not stated, demoed | 40:48 | |
| Error info data type | status not stated, demoed | 42:32 | |
| Fix-it actions in error dialog | status not stated, demoed | 42:32 | |
| Error behavior collect | status not stated, demoed | 45:13 | |
| Collectible errors in error info | status not stated, demoed | 45:50 | |
| Free show-it feature since BC 24 | status not stated, demoed | 44:53 | |
| Transaction Handling Checklist | status not stated | 52:07 | |
| Try Function Behavior: On-Premise vs Online | status not stated | 56:35 |
AL objects mentioned
As heard in the captions. A name that matches one object page by exact type and name links to it; the others stay as named.
Not found in BC28-30: codeunit “Parallel Worker”, codeunit “Sales post”, codeunit “codeunit.run”.
Quotes
- 5:47 “What is a transaction itself? Well, a transaction is a group of database changes that succeed together or fail together.”
- 6:37 “In AL, the runtime does it for you. When AL code needs a transaction, the runtime starts one. And when the code finishes, the”
- 10:42 “It’s undoes inserts, modifies, and deletes on normal tables since the last commit. But, not undone. Your variables, temporary records, single instance could you”
- 11:38 “Posting preview. So, let’s imagine we have general uh posting preview could you need which really post into real tables data.”
- 14:00 “The error was caught, but the right inside the try function wasn’t undone. That’s how it works online.”
Disclaimers in the video
- 4:56 other: Microsoft MVP since 2025
- 14:14 other: On premises, the seller blocks any rights inside try methods by default.
- 37:15 subject-to-change: the documentation says this behavior might change in upcoming release
- 55:28 other: I think it will be bad because it’s not how publisher works by default
Presenters (as heard): Luke, Volodymyr Vernitsky, Vlado.
