Codex + Custom Apex vs Codex + ZeroExport MCP: AI-Written Code Is Still Code

OpenAI Codex can write a custom Salesforce document generator quickly. But every line becomes code you test, deploy and maintain. How connecting Codex to the ZeroExport DocGen MCP server avoids that debt.
OpenAI Codex is fast at Apex. Give it a spec for a quote PDF and it will produce a controller, a Visualforce page and a test class before your coffee cools. That speed makes it tempting to skip a document generation product altogether.
The catch is simple: AI-written code is still code. It needs tests, review, deployment and an owner, every time the document changes. This post looks at what that means for Salesforce documents, and at the alternative: connecting Codex to the ZeroExport DocGen MCP server so it builds templates instead of code.
The code you sign up for
A custom Apex document generator is more than one class. A realistic one includes:
- Data access: queries for the record, its children and grandchildren, written to avoid queries inside loops.
- Rendering: a Visualforce page or HTML builder, with CSS that the Salesforce PDF renderer actually supports.
- Table logic: grouping, merged cells, subtotals and repeated headers across pages.
- Edge cases: null lookups, empty related lists, long text and very large line-item counts.
- Tests: at least 75% org-wide coverage to deploy, and tests that cover the cases above to be safe.
- Deployment: a change set or pipeline for every update.
Codex can write all of it. Your team then owns all of it.
Three ways the debt shows up
1. Governor limits appear at production volume
Generated code tends to be correct at the size of the test data. Synchronous Apex is limited to 10 seconds of CPU and 6 MB of heap. HTML built by string concatenation in nested loops passes a five-line test and fails on a 500-line bill of materials. You find out in production, from a user.
2. Each change request becomes a release
A new clause, a new column or a new logo means a code change, updated tests and a deployment. Admins cannot make the change themselves, so requests queue behind developer time. Codex shortens the coding step but leaves the release process and the dependency on a developer. This is the DocGen debt that custom builds accumulate.
3. Prompts are not a spec
When Codex regenerates part of the generator for a new requirement, the change has to be reviewed like any other code change. The original edge-case handling can be lost, because nothing outside the code records what the document must do. Over time you have a generator nobody fully understands, written partly by a model.
Codex + ZeroExport MCP: templates, not code
With the ZeroExport MCP server connected, Codex works on templates for a native engine that already exists. ZeroExport is a managed package that compiles and renders documents in Apex inside your org. Codex's job becomes:
- Read your org's schema through the MCP server, read-only, so field and relationship names are real.
- Write a ZeroExport template: data sources, layout, grouping, totals and visibility rules.
- Fix what ZeroExport's validator reports. The validator runs in your org, including a dry-run import that is rolled back.
- Import an inactive draft after you confirm. The draft is compiled like any template saved in the builder.
What you do not own: the rendering engine, its tests, its governor-limit tuning or its deployments. Those come with the package. Grouping, merged cells, subtotals and nested data up to five levels are template features, not code to write. Fail-closed checks stop generation when required data is missing, so a document with gaps is never produced.
What you do own is a set of templates that admins can open, edit and activate in the Lightning builder.
Side by side
| Codex + custom Apex | Codex + ZeroExport MCP | |
|---|---|---|
| Output | Apex, Visualforce/HTML, CSS, tests | A validated ZeroExport template |
| Who can change it | Developers | Admins in the builder, or Codex again through MCP |
| Release process | Tests and a deployment for every change | Save and activate a new template version |
| Large documents | Your code against CPU and heap limits | A compiled engine built for many rows |
| Complex tables | Custom code | Built-in grouping, merges and subtotals |
| Org access | Whatever your deployment pipeline allows | Read-only schema, plus one template import you approve. No metadata changes possible |
| AI at generation time | None | None |
When writing the code is fine
For a single, simple, stable document with low volumes and a developer who will own it, a custom build is reasonable, and Codex will write it well. For anything with grouped tables, large line-item counts, frequent changes or many templates, the code is the expensive part, and the MCP approach removes it. For a broader cost comparison, see the real cost of Salesforce DocGen.
FAQ
Does the ZeroExport MCP server work with Codex?
Yes. Codex and other MCP clients such as Claude Code connect to the server, which runs on your own machine. It is included in the Standard plan from ZeroExport 1.13.
Does Codex write Apex when using the MCP server?
No. It writes ZeroExport templates. The server cannot deploy code or change org metadata.
Is an AI model involved when documents are generated?
No. Documents are generated by ZeroExport's deterministic Apex engine inside Salesforce, with no AI model and no external call.
Related Reading
Ready to try ZeroExport?
Start generating documents directly in your Salesforce org. No integrations, no setup overhead, no complexity.