SfSkills Domains Docs GitHub

Home / data / data-archival-strategies

data-archival-strategies

Use when planning how to archive aging Salesforce records to reduce storage costs, maintain query performance, and meet retention policies.

Open the skill folder on GitHub


Data Archival Strategies

Use this skill when an org needs to move aging records off its main objects, for storage, query performance, or a retention policy, and has to choose where they go and how they come back. It does not cover migrating data to a new org (use data/data-migration-planning) or a delete-only retention job (use data/batch-data-cleanup-patterns).


Before Starting

Gather this context before working on anything in this domain:


Questions to Ask Before Configuring

AskWhy it mattersWhat a good answer adds
"What exact questions will someone ask of the archive, and by which fields?"A big object is queried along its index, and the index cannot be changed after deployment (Gotcha 7)An index designed from retrieval questions, in the right field order
"Has anyone run the restore or audit query end to end before the source is deleted?"The write path can work for months before anyone discovers the read path does not (Gotcha 2)A tested read path, signed off before the first delete
"Is the goal storage, query speed, or both?"Emptying the Recycle Bin helps queries but frees no storage, because Recycle Bin rows don't count against storage (Gotcha 3)The right lever for the actual pain
"Do auditors need field-level change history for these records, and for how long?"Deleting a record cascades to its field history; standard history is kept 18 months (24 via the API) unless Field Audit Trail is on (Gotcha 4)A Field Audit Trail policy, or an export, in place before deletion
"What happens when an archive write half-fails?"insertImmediate returns errors instead of throwing, and partial batch failures are expected (Gotcha 5)A retry-the-whole-batch loop and a delete that only runs after a clean write
"Does the archive job do any other DML in the same transaction?"Big object DML is treated as a callout, and callouts aren't allowed after DML in the same transaction (Gotcha 6)An execute method that writes the big object first
"Is any source data encrypted with Shield Platform Encryption?"Custom big objects don't support encryption; archived values are stored as clear text (Gotcha 8)A decision on which fields may be archived at all

A proper archival design adds a tested read path, an index built from real questions, and a delete step gated on verified writes; "export and delete" leaves the org with records nobody can retrieve and storage that did not move.


Core Concepts

What counts toward storage

DataCounts against data storage?Source
Records in standard and custom objectsYes—
Records in the Recycle BinNo; the bin has no item limitLDV guide, Deleting Data
Field history tracking and Field Audit Trail dataNoSecurity guide, Field History Tracking

Soft-deleted rows still affect query performance: they remain resident and have to be excluded from every query. Deleted items stay 15 days, then are scheduled for hard deletion with no guaranteed time.

Big objects

BehaviourDetail
EditionsEnterprise, Performance, Unlimited, and Developer (Developer up to 1 million records); up to 100 big objects per org
WritesDatabase.insertImmediate(); reinserting the same index values overwrites (upsert-like) and is idempotent; DML on big objects is treated as a callout and doesn't count toward the DML statement limit
DeletesDatabase.deleteImmediate() or SOAP deleteByExample(), with every index field specified; 50,000 records per call
IndexRequired fields only; no LongTextArea or URL; text fields in the index total at most 100 characters; cannot be edited after deployment
APIsSOQL, Bulk API and Bulk API 2.0, Chatter, and SOAP only; the REST API isn't supported
Not supportedTriggers, flows, processes, the mobile app, sharing rules (object and field permissions only), standard list views and detail pages, encryption for custom big objects

UNVERIFIED (2026-10-19): the 100-big-objects-per-org cap, DML treated as a callout and not counted toward the DML statement limit, SOAP deleteByExample(), and the list-view, detail-page, and encryption entries come from Big Objects Implementation Guide pages that are not in the Summer '26 PDF corpus. The corpus confirms the editions and Developer 1M cap, idempotent writes, the API list with REST unsupported, the index rules, and the unsupported triggers, flows, processes, mobile app, and sharing rules (Object Reference L3530-3700); insertImmediate partial success without an exception (Apex Reference L208300-208303); and the 50,000-record deleteImmediate batch limit (Apex Reference L206805).

<?xml version="1.0" encoding="UTF-8"?>
<!-- objects/Case_Archive__b.object (Metadata API format). Index fields must be required. -->
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
    <deploymentStatus>Deployed</deploymentStatus>
    <fields>
        <fullName>Account__c</fullName>
        <label>Account</label>
        <referenceTo>Account</referenceTo>
        <relationshipName>Case_Archives</relationshipName>
        <required>true</required>
        <type>Lookup</type>
    </fields>
    <fields>
        <fullName>Closed_Date__c</fullName>
        <label>Closed Date</label>
        <required>true</required>
        <type>DateTime</type>
    </fields>
    <fields>
        <fullName>Case_Number__c</fullName>
        <label>Case Number</label>
        <length>30</length>
        <required>true</required>
        <type>Text</type>
    </fields>
    <fields>
        <fullName>Subject__c</fullName>
        <label>Subject</label>
        <length>255</length>
        <required>false</required>
        <type>Text</type>
    </fields>
    <indexes>
        <fullName>CaseArchiveIndex</fullName>
        <label>Case Archive Index</label>
        <fields>
            <name>Account__c</name>
            <sortDirection>ASC</sortDirection>
        </fields>
        <fields>
            <name>Closed_Date__c</name>
            <sortDirection>DESC</sortDirection>
        </fields>
        <fields>
            <name>Case_Number__c</name>
            <sortDirection>ASC</sortDirection>
        </fields>
    </indexes>
    <label>Case Archive</label>
    <pluralLabel>Case Archives</pluralLabel>
</CustomObject>

Field history

Without Field Audit Trail, field history is kept up to 18 months (24 months via the API), and up to 20 fields per object can be tracked. With Field Audit Trail, a HistoryRetentionPolicy deployed through Metadata API copies history into the FieldHistoryArchive big object and keeps it until you delete it; up to 200 fields per object can be tracked. By default the archive happens after 18 months in production and one month in sandboxes. Deleting a production record cascades to its history rows but not to the copy in FieldHistoryArchive. Field history can be deleted manually at any time.


Common Patterns

Pattern 1: Big object archive with a gated delete

  1. Design the index from the audit questions; deploy the big object and a permission set (access is restricted by default).
  2. Batch over the source with a selective start query (oldest closed records first).
  3. In execute, build big object rows with trimmed index values, call Database.insertImmediate() before any sObject DML, and check every SaveResult; on any failure, retry the whole batch rather than picking out failures.
  4. Delete source rows only for a fully written batch, then call Database.emptyRecycleBin() (10,000 records per call; it counts as a DML statement) if query performance on the source matters.
  5. Before the first production delete, run the read path: a SOQL query on the index prefix and a Bulk API 2.0 query job for volume.

Pattern 2: Soft archive on the same object

Add Is_Archived__c and filter it out of list views and queues when records must stay in standard reports. Storage does not change; only clutter and query scope do. Ask Support for a custom index if the flag must drive queries.

Pattern 3: External archive

Move rarely read data to an external store when cost matters more than in-org access. Decide first how users will reach it (Salesforce Connect external object, a link, or an integration) and how lookups from active records will behave.


Decision Guidance

SituationRecommended approachReason
Must stay queryable in Salesforce along known keysBig object with an index built from the questionsConsistent performance at very large volume; stays on platform
Must stay in standard list views and reportsSoft archive flag on the source objectBig objects use custom components, not standard list views or detail pages
Rarely read, cost is the driverExternal storeNo Salesforce data storage used
Queries slow after a mass deleteEmpty the Recycle Bin, or use Bulk API hard delete next timeSoft-deleted rows still affect queries
Storage alert after a mass deleteDo not count on emptying the Recycle BinRecycle Bin rows don't count against storage
Field changes must be kept beyond 18 monthsField Audit Trail retention policyStandard history is kept up to 18 months (24 via the API)
Source fields are Shield-encryptedKeep them out of custom big objects, or accept clear textCustom big objects don't support encryption

  1. Fill templates/data-archival-strategies-template.md with the storage baseline, candidate objects, retention rules, and the read questions for each object.
  2. Pick the destination per object with Decision Guidance; for big objects, write the .object file (or objects/<Name>__b/ source folder) and a permission set.
  3. Run python3 skills/data/data-archival-strategies/scripts/check_data_archival_strategies.py --manifest-dir force-app/main/default and fix every ERROR (index rules, required index fields, text length) before deploying; review WARN lines on field history tracking.
  4. Build the archive batch from references/examples.md, and write Apex tests that mock the big object writes with the Stub API (tests write real big object data with no rollback).
  5. In a full-copy sandbox, run the job on a sample, then run the read path (SOQL on the index prefix and a Bulk API 2.0 query job, as in references/read-path-worked-example.md) and have the data owner sign off.
  6. Enable the production schedule with deletion gated on verified writes; re-check Storage Usage and source query plans after the next run.

Review Checklist


Salesforce-Specific Gotchas

Full write-ups are in references/gotchas.md:

#Gotcha
1Big object rows cannot be changed with standard DML
2The read path is the part nobody tests until it is too late
3Emptying the Recycle Bin helps queries, not storage
4Deleting a record deletes its field history too
5insertImmediate reports failures instead of throwing
6Big object writes are callouts, so order matters in a transaction
7A big object index is permanent and tightly constrained
8Custom big objects store encrypted source data as clear text
9Whitespace and nulls behave unexpectedly in big object writes

Output Artifacts

ArtifactDescription
Archival strategyDestination per object with the read questions it must answer
Big object definition.object file with fields and index, plus a permission set
Archive batchApex job with gated delete and retry
Read-path proofThe SOQL and Bulk API 2.0 queries run against archived data, with results
Filled templatetemplates/data-archival-strategies-template.md

Package files