ORGZIP / GUIDES

How to let Agentforce read archived Salesforce emails without blowing up Data Storage

When you archive old Email-to-Case emails to cut Salesforce Data Storage costs, AI agents normally lose sight of them. A 100% Native Invocable Apex Action lets Agentforce, Prompt Builder and Flows read archived Case history on demand — with quoted reply chains stripped and live Case sharing plus FLS enforced.

  • By OrgZip
  • Updated November 29, 2026

Why archiving usually breaks Agentforce

Short answer: Agentforce grounds its responses on live Salesforce records and configured actions. Once closed-Case EmailMessage, CaseComment, Task or Event records are purged from Data Storage — or converted into flat PDFs or pushed to an external cloud — standard Case queries return nothing for that history.

Teams then face an expensive trade-off: either pay for extra Salesforce Data Storage to keep years of old emails live so AI agents stay informed, or archive aggressively and accept that Agentforce misses prior refund promises, RMA numbers and recurring escalations.

Because OrgZip stores compressed archive bundles natively inside Salesforce Files in your own org, an Apex Invocable Action can read the relevant parent record’s archived history in real time, strip repetitive quoted replies, and pass clean chronological text straight into Agentforce or Prompt Builder — without restoring a single record back to Data Storage.

How archiving approaches compare for Agentforce

Comparison of Salesforce archiving methods for Agentforce grounding
ApproachFrees Data Storage?Agentforce can read old emails?Live Case sharing & FLS
Keep emails live in SalesforceNo — Data Storage keeps growing.Yes, via standard Case context, but raw HTML and quoted threads waste tokens.Native Salesforce sharing and FLS.
Convert Case emails to PDFYes, after deleting source emails.Not as structured Case email history; requires separate file extraction.Follows file sharing, not field-level email security.
Off-platform archive (external cloud)Yes.Requires external API callouts, credentials and custom integration.Often requires rebuilding or syncing sharing rules outside Salesforce.
100% Native ZIP archive + Invocable Action (OrgZip)Yes — moves heavy bodies into compact ZIP files in File Storage.Yes — native Get Archived Record History action returns clean text + JSON.Checked live on every call (Archive_Viewer, UserRecordAccess, FLS).

Inside OrgZip’s native Invocable Action

OrgZip ships a global invocable Apex method labeled Get Archived Record History (category OrgZip, class ArchiveAgentAction). Because it is standard Invocable Apex, it works across Agentforce Agent Actions, Prompt Builder (via Flow or Apex), and Screen or Autolaunched Flows.

Inputs supported by Get Archived Record History
Input variableRequiredDefault / RangeWhat it does
parentIdYesCase, Account or parent IDIdentifies the parent record whose archived history should be retrieved.
objectApiNameNoEmailMessage (or CaseComment, Task, Event, custom object, ALL)Scopes retrieval to one archived object or merges across all accessible archived objects.
searchTermNoBlank (all records)Filters archived records by keyword across subject, sender, recipient, body and original ID.
maxRecordsNo10 (range 1–25)Caps how many newest-first matching archived records are returned.
maxCharactersNo8,000 (range 500–32,000)Fits the formatted summary cleanly inside your prompt’s token budget.
stripQuotedTextNotrueRemoves repetitive quoted email reply chains to maximize AI context signal.
Outputs returned by Get Archived Record History
Output variableTypeHow Agentforce or Flow uses it
summaryTextStringClean, chronological plain-text summary (with object label, date, From/To, stripped body and attachment titles) ready for direct prompt grounding.
recordsJsonStringStructured JSON array of FLS-masked archived records for downstream parsing or custom UI.
recordCountIntegerExact count of archived records included in the response.
truncatedBooleantrue when additional matching records or characters exceeded the configured limits or CPU guardrail.

How to wire archived history into Agentforce, Prompt Builder and Flows

  1. Assign the viewer permission. Grant the ArchiveViewer permission set (which includes the Archive_Viewer custom permission) to the running user or Agentforce service user. Do not grant ArchiveAdmin to an AI agent.
  2. Register the Agent Action. In Setup → Agentforce Assets (or Flow Builder), create an Apex action pointing to Get Archived Record History under category OrgZip.
  3. Give clear instructions to the agent. Tell the agent when to invoke it — for example: “When a customer references an older Case, prior refund, invoice or past email not visible in live Case emails, call Get Archived Record History with the Case ID and optional searchTerm.”
  4. Keep stripQuotedText = true and tune maxCharacters. The default 8,000-character budget fits comfortably in most Service Agent and Case Summary prompt templates without crowding out live fields.
  5. Test with a restricted user in a sandbox. Verify that an agent running as a user without access to a confidential Case receives no archived records for that Case, and that restricted custom fields remain masked.

Security, sharing and Apex governor guardrails

  • Live permission enforcement: The class runs with sharing, checks the Archive_Viewer custom permission upfront, verifies current parent record access via UserRecordAccess, and applies current Salesforce field-level security (FLS) to every returned field.
  • Zero Data Storage write-back: Reading archived history happens in memory from compressed ZIP bundles in Salesforce Files. Records stay archived and never inflate Data Storage again.
  • Predictable governor protection: Each call inspects up to 200 candidate manifests and scans up to 20 matching bundles (capped at 100 matched records and 60% of the Apex CPU time limit). If a parent has an unusually deep archive, the action stops safely and sets truncated = true so your prompt or agent knows more history exists.
  • Transparent boundary: Archived emails are still not indexed by Salesforce Global Search or standard Salesforce Reports while archived. Use this action for targeted record-context retrieval (Case, Account or parent record) and OrgZip Archive Search for interactive team queries.

Full data-flow and permission details are on Security and data handling. Ready to test in a sandbox? Follow the 5-minute install guide.

Questions

Can Agentforce read archived EmailMessage records in Salesforce?

Standard Salesforce archiving removes records from live tables, so Agentforce cannot see them through normal SOQL or standard Case lookups. With a native Invocable Apex Action like OrgZip’s Get Archived Record History, Agentforce, Prompt Builder and Flows retrieve archived emails, Case comments, Tasks, Events or custom records on demand without restoring them to Data Storage.

Does giving Agentforce access to archived emails bypass Salesforce sharing or FLS?

No, if the action enforces live access controls. OrgZip’s ArchiveAgentAction runs with sharing, requires the Archive_Viewer permission, checks current parent record access via UserRecordAccess on every request, and masks fields using current field-level security before returning summaryText or recordsJson.

Why should quoted email reply chains be stripped before sending archived threads to Agentforce?

Email-to-Case threads repeat earlier messages at the bottom of every reply. Sending raw threads wastes prompt context tokens and dilutes retrieval quality. OrgZip’s stripQuotedText option defaults to true, keeping each unique message turn clean and chronological inside the character budget.

Does querying archived history for Agentforce consume Salesforce Data Storage again?

No. The Invocable Action reads compressed ZIP snapshots directly from Salesforce Files in memory and returns formatted text or JSON to the agent or flow. Nothing is restored or written back into Data Storage.

How many archived records can one Agentforce action call return?

OrgZip’s Get Archived Record History returns 1 to 25 records per call (default 10) and up to 32,000 characters of formatted summary text (default 8,000). It also enforces Apex governor safety limits (scanning up to 20 matching bundles and stopping at 60% CPU time) and sets the truncated output flag to true if more matches exist.

Keep reading

Salesforce archiving options compared

Delete and export, Big Objects, Salesforce Archive, off-platform apps and 100% Native, with trade-offs.

Read the guide

How much storage does a Salesforce email use?

EmailMessage storage measured in a test org: body size, the Recycle Bin, and what archiving freed.

Read the guide

Case emails to PDF, or archive them?

What a PDF keeps and loses compared with an archive: search, reply, restore and cost.

Read the guide

Keep Agentforce informed without paying for old email storage.

Install OrgZip in a sandbox, archive a sample of closed-Case emails, and test Get Archived Record History directly in Flow or Agentforce.

Get a read-only assessment