---
schema_version: "1"
id: 538470eda77d03ef9115d5f9f59678aeca869d2c9a41e99053a7bd3c103012ad
title: Get Started with Archive Policies
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/xcloud/264-0-0/archive_get_started_with_archive_policies.md
canonical_url: https://help.salesforce.com/s/articleView?id=xcloud.archive_get_started_with_archive_policies.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: b2730b38979a28508c3cc7b59c9b42f7f08d40c88481f9c2c72c722146cf35cd
description: Use the Archive app to create automated, scheduled policies that manage your data's lifecycle.
products:
  - Salesforce Platform
  - Cross Cloud
release: "264"
---
# Get Started with Archive Policies

Use the Archive app to create automated, scheduled policies that manage your data's lifecycle.

## Archive Policies

An archive policy defines the criteria for moving data from production into your archive. When you create this policy, you also set its initial retention period.

An archive policy uses a single condition, such as `LastModifiedDate > 365 days ago`, to identify which records to archive.

An archive policy also sets a simple, default retention period, such as "Delete 7 years after archive date." The retention period sets the archived record's initial expiration date.

## Purge Policies

A purge policy defines the criteria for permanently deleting data that's stored in your archive.

The purge policy changes the default retention period set by the archive policy and gives you more power and flexibility to manage data destruction.

For example, you can purge certain record types sooner, such as `Record Type = 'Test Data' AND Archived Date > 1 year`, while keeping more critical records longer, such as `Record Type = 'Financial' AND Archived Date > 10 years`, regardless of the default 7-year retention set during the archive policy.

## Key Questions Before You Begin

A good policy starts with a good plan. Before you start building, discuss these key questions with your stakeholders.

What to Archive?

- Which root objects and their related child records must be archived? For example, closed cases, old tasks, or custom project records.
- What's the business driver? Are you trying to improve performance, reduce storage costs, or meet a specific compliance requirement?

When to Run?

- How often do you want the archive and purge policies to run? For example, daily, weekly, or monthly.
- What specific time and day must the archive and purge policies run?
    
    ![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-xcloud-setup-264-0-0-production-enus/6f21df35-9ea0-4f53-ac94-45c3b5dfd5bc/images/icon_note.png)
    
    Note To reduce any possible impact on your users and system performance, run large archive or purge processes during off-peak hours, such as nights and weekends.

Who Has Access?

- Who's responsible for creating and managing these archive and purge policies?
    
    ![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-xcloud-setup-264-0-0-production-enus/6f21df35-9ea0-4f53-ac94-45c3b5dfd5bc/images/icon_note.png)
    
    Note Typically a system admin, but you can assign the Archive permission sets to the appropriate admins.
- Who needs to view data after it's been archived? For example, admins, auditors, or specific support teams.
- Who requires permission to unarchive records from your archive and restore them back to your live org?
    
    ![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-xcloud-setup-264-0-0-production-enus/6f21df35-9ea0-4f53-ac94-45c3b5dfd5bc/images/icon_note.png)
    
    Note The Unarchive permission sets control this capability. Assign these permission sets only to specific users who require it.

## Policies Don't Clone to Sandbox

When you clone a full sandbox from production, Archive policies aren't copied to the sandbox environment. Unlike other Salesforce configurations, manually recreate your policies in the sandbox.

![Important](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-xcloud-setup-264-0-0-production-enus/6f21df35-9ea0-4f53-ac94-45c3b5dfd5bc/images/icon_important.png)

Important Plan to recreate your policies in the sandbox after cloning from production.

## Use Cases and Queries

For testing purposes, we recommend starting with a low archive policy limit.

## Example: Archive Tasks

Object: Task

Use Case: Archive Tasks that meet these criteria.

- Related to record type of Case
- RecordTypeID = 'abc'
- Last modified more than 2 years ago

`LIMIT = 5` archives 5 Tasks in each run, and their related objects.

Preview: Id, Activity Date, Category (custom field), Description, Owner ID, Subject, Status

```
SELECT Id FROM Task WHERE Whold IN (SELECT Id FROM Contact 
WHERE RecordTypeid = 'abc') AND ActivityDate<LAST_N_DAYS: 730 LIMIT 5
```

## Example: Archive Cases

Object: Case

Use Case: Archive Cases that meet these criteria.

- Status is set to 'Closed'
- Created more than 30 days ago

`LIMIT = 5000` archives 5000 Cases in each run, and their related objects.

Preview: Id, Case Number, Type, Sub Category (custom field), Issue (custom field)

```
SELECT Id FROM Case WHERE Status = 'Closed' 
AND CreatedDate < LAST_N_DAYS: 30 LIMIT 5000
```

## Example: Archive Cases from a Specific Account

Object: Case

Use Case: Archive Cases that meet this criteria.

- Status is set to 'Closed'
- Created more than 30 days ago
- Belongs to an account with ID number '1234'

`LIMIT = 5000` archives 5000 cases in each run and its related objects.

Preview: Id, Case Number, Type, Sub Category (custom field), Issue (custom field)

```
SELECT Id FROM Case WHERE accountId IN (SELECT id from Account 
WHERE Id ='1234XXXXXXXXXXXXXXX') AND Status = 'Closed' 
AND CreatedDate < Last_N_Days:30 LIMIT 5000
```

## Example: Archive Attachments

Object: Attachment

Use Case: Archive attachments where:

- Parent is an Opportunity in a stage that is either 'Signed Off' or 'Asbestos Completed.'
- Opportunity Close Date is more than 6 months in the past.

`LIMIT = 2500` archives 2,500 attachments in each run, and its related objects

Preview: Id, Parent ID, Created Date

```
SELECT Id FROM Attachment WHERE ParentId IN (SELECT Id FROM Opportunity 
WHERE (StageName='Signed Off' OR StageName='Asbestos Completed') 
AND CloseDate < N_MONTHS_AGO:6) LIMIT 2500
```

## Example: Archive Contacts

Object: Contact

Use Case: Archive contacts where:

- `Archiver__c` field is set to `True`

`LIMIT = 1000` archives 2,500 contacts in each run, and its related objects.

Preview: Id, Parent ID, Created Date

```
SELECT Id FROM Contact WHERE Archiver__c = true LIMIT 1000
```

## Archive Queries Best Practices

To improve the success of Archive queries, consider these recommendations.

- Write conditions on indexed fields. The complexity of the SOQL query enormously influences whether a field is suitable for indexing. Standard and custom indexes are different.
- Consult the [Query & Search Optimization Cheat Sheet](https://resources.docs.salesforce.com/194/0/en-us/sfdc/pdf/salesforce_query_search_optimization_developer_cheatsheet.pdf).
- Limit the result set to a manageable size‌. Retrieving too many records at one time can trigger table scans, which are significantly slower than indexed lookups.
- Avoid overly broad filters that match large volumes of data. If needed, split your date ranges into smaller batches to reduce query load.
- Validate filter logic regularly to ensure you're targeting only the records that must be archived.
- Monitor process logs to identify recurring performance bottlenecks or records that fail to proceed through the entire process lifecycle.
- Filter query results by using dates. For more information, see [Date Formats and Date Literals in WHERE](https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_dateformats.htm).
- Reference the `SystemModstamp` rather than the `LastModifiedDate`.
    
    `LastModifiedDate` is user-driven and updates when users change records. `SystemModstamp` is system-driven and updates when a record is modified by the system, including automation and back-end processes. Queries that use `SystemModstamp` tend to perform better because they're indexed.
- Consider that Force.com has its own SOQL query optimizer. For more information, see [Lightning Platform Query Optimization FAQ](https://www.salesforce.com/resource/Lightning-Platform-query-optimization-FAQ).

## Optimize Archive Queries

When you run queries in Salesforce, it's important to make sure that they're optimized to improve efficiency and avoid performance issues, especially when you're working with large datasets.

A common issue is that certain filters can trigger a full-table scan, which negatively impacts performance. For example:

```
SELECT Id FROM EmailMessage WHERE ParentId IN (SELECT Id FROM Case 
WHERE IsClosed = true) AND LastModifiedDate < LAST_N_MONTHS:13 LIMIT 350000
```

Problems with this query:

- `IsClosed` isn't a selective filter, meaning it doesn't use an index efficiently.
- `LastModifiedDate` can return more than 1 million records, which prevents the use of an index.
- To take full advantage of query optimizations, index the queried object in Salesforce.
- To improve efficiency, remove the `IN` subquery.

To optimize the query:

- Remove the `IN` subquery, which reduces unnecessary complexity.
- Make sure that the object is indexed.
    
    Queries on non-indexed objects don't benefit from performance optimizations.
- Turn on the Query Plan setting in the Developer Console.
    
    The Query Plan setting analyzes query selectivity. To turn on this setting, go to Preferences under Help in the Developer Console.
- Modify these filters.
    - Change `Parent.IsClosed` to an indexed field.
    - Use `SystemModstamp` instead of `LastModifiedDate`, as `SystemModstamp` is indexed and more efficient.
    - To reduce the number of records scanned, narrow the date range. For example, `<13` and `>15`.

Here's the new, more efficient query.

```
SELECT Id FROM EmailMessage WHERE Parent.IsClosed = true 
AND LastModifiedDate < LAST_N_MONTHS: <13 and >15 LIMIT 350000
```