How to Document a Salesforce Org for AI Coding Agents

To document a Salesforce org for an AI coding agent, export its data model as plain text: every object, field, type, picklist, relationship, validation rule and record type, plus how access is granted. Markdown organized as one file per object, with an index and a build order, fits a context window better than raw metadata XML or describe JSON.

The reason you need this at all is simple: a coding agent can't click around Setup. Whether you're asking it to write an integration, port part of your CRM to Postgres, write tests, or just explain why an insert keeps failing, it can only reason about what's in its context. If the org's shape isn't there in text, the agent guesses — and it guesses confidently.

Why do AI coding agents need the org's data model in text?

Because the agent's only view of your org is what you paste, attach or point it at. Salesforce keeps most of its meaning in metadata: a field called Status__c might be a restricted picklist with seven values, a required lookup, or a formula. None of that is visible from Apex code alone, and an agent that doesn't see it will invent plausible-but-wrong values, skip required fields, or model a master-detail as a nullable foreign key.

A good org document turns those implicit agreements into explicit facts the agent can cite. It also gives you something to review: when the agent proposes a schema, you can check it against the doc instead of against your memory.

What should the documentation capture?

Capture everything that constrains what valid data and valid code look like. In rough order of how often it matters:

Area What to include Why the agent needs it
Objects API name, label, standard vs custom, description Maps entities to tables/classes
Fields API name, type, length/precision, required, unique, external ID, default Prevents type and nullability mistakes
Picklists Values, restricted or not, global value set, dependencies Stops invented enum values
Relationships Lookup vs master-detail, target object, cascade behavior Drives foreign keys and insert order
Formulas Formula text and return type Derived fields shouldn't be written to
Validation rules Error condition formula and message Explains "why did my insert fail"
Record types Names and which picklist values each allows Picklist validity is per record type
Automation Flows, triggers, approval processes that fire on the object Side effects the agent must not duplicate
Access Object and field permissions by profile / permission set What a given user can actually see and edit
Page layouts Which fields appear where, and on which layout UI rebuilds and "required on layout" quirks

Two things to deliberately leave out: record data (the agent needs the schema, not your customers — and it keeps PII out of prompts) and managed-package internals you can't change anyway.

Which format works best: Markdown, metadata XML, or describe JSON?

Markdown is usually the best fit for an agent; XML and JSON are better as raw inputs to produce it. The trade-offs come down to token cost, completeness and how easily a model can navigate the result.

Format Token cost Completeness Navigability Best use
Raw Metadata API XML High — verbose tags, many files High for what you retrieve Poor: facts scattered across object, layout and permission files Source of truth; deploys
Describe JSON (per object) High — every field carries dozens of properties Good for fields, types, picklists, relationships; no validation rule formulas or layouts Poor at org scale Programmatic generation
Markdown tree (one file per object + index) Low — only the facts that matter, as tables As good as whatever you put in Good: agent reads the index, then opens only what it needs Agent context

The key idea is progressive disclosure. An agent working on the Opportunity trigger doesn't need 400 objects in its context; it needs an index that tells it where Opportunity lives, then the one file. A tree of small Markdown files with cross-links lets it pull in only what the current task touches, which keeps the context budget for your actual code.

A single giant Markdown file works for small orgs. Past a few dozen objects, split it.

How do you produce org documentation manually?

You can build it yourself with Salesforce CLI and a script. The rough workflow:

  1. Generate a manifest of what's in the org with sf project generate manifest --from-org <alias>, then trim it to the types you care about (CustomObject, Layout, Profile, PermissionSet, Flow, and so on).
  2. Retrieve the source with sf project retrieve start --manifest package.xml. Object folders contain field, validation rule and record type XML; layouts and permission files come down separately.
  3. Describe each object with sf sobject describe --sobject Account (JSON output). This fills in runtime facts like resolved picklist values and relationship names.
  4. Transform to Markdown. Write a script that walks the retrieved folders and describe output and emits one file per object: a field table, picklists, relationships, validation rules, record types.
  5. Add the glue. An index of objects, a note on what the doc does not cover, and a dependency-ordered list of objects (parents before children) so an agent rebuilding the model knows where to start.
  6. Commit it next to your code and regenerate when the schema changes.

The retrieve and describe steps are easy. Step 4 is where the time goes: stitching fields to their record types, resolving global value sets, and computing a sensible build order from lookups is a real piece of code to maintain. It's worth it if you document one org you care deeply about; it's a slog if you have several.

How do you keep the documentation honest?

Generate it from metadata, never from memory, and say what's missing. If you use an LLM to write readable summaries on top, keep the structural facts (types, values, rules) extracted deterministically and let the model only narrate them. An agent can't tell a hallucinated picklist value from a real one, so the doc must not contain any.

A short "coverage" section — "this document does not describe Apex, sharing rules or integrations" — does a surprising amount of work. It tells the agent to flag a gap instead of filling it.

Generating it with Syntharil MetaSwitch

If you'd rather not maintain the transform script, MetaSwitch does this for a connected org. It introspects the data model — objects, fields, relationships, picklists, formulas, record types and validation rules — and writes a Markdown tree with an index, a per-object file for each object, a coverage file listing what isn't captured, and a dependency-ordered rebuild sequence. Medium and Detailed levels also include page layouts, Lightning pages and profile/permission set access. There are four detail levels (Basic, Medium, Detailed, Custom); structure is extracted deterministically, and an LLM only adds readable narratives grounded in the real metadata. The output downloads as a zip. It doesn't yet capture Apex, Flows or sharing rules, and it says so in the bundle, so pair it with your code repo for those.

Bottom line

AI coding agents are only as good as the context you give them, and a Salesforce org keeps most of its meaning out of sight. Document the data model, rules and access as small, cross-linked Markdown files generated straight from metadata; state what's not covered; and regenerate when the schema changes. Build the pipeline yourself with sf if you have one org and time, or generate it if you'd rather spend that time on the work the agent is helping with.

FAQ

Can an AI coding agent read Salesforce metadata XML directly?

Yes, but it's an inefficient use of context. Retrieved metadata is verbose, split across many files, and mixes structural facts with UI and packaging noise, so an agent burns tokens before it reaches the parts that matter.

Should I include record data when documenting an org for an AI agent?

Usually not. The agent needs the schema and the rules, not customer records. Leaving data out keeps the document small and keeps PII out of your prompts.

How often should I regenerate org documentation for an agent?

Regenerate whenever the data model changes in a way the agent's task depends on — new objects, new fields, changed picklists or validation rules. Stale docs are worse than none because the agent will trust them.

What's the difference between describe JSON and a Metadata API retrieve?

Describe calls return the runtime shape of an object — fields, types, picklist values, relationships — as JSON. A Metadata API retrieve returns the source definitions as XML files, which include things describe doesn't, such as full validation rule definitions, layouts and permission files.

Related reading

Try Syntharil free