---
id: object/codeunit/3910
type: object
title: Codeunit 3910 "Apply Retention Policy"
summary: Codeunit 3910 "Apply Retention Policy" in System Application (System.DataAdministration). 8 public procedures, 3 events. Present since at least BC23, still in BC30, changed in BC28.
tier: official
language: en
tags:
  - codeunit
  - system application
versions:
  introduced: null
  last_changed: "28"
  deprecated: null
review:
  state: derived
  by: null
  at: null
  flags: []
generated:
  at: "2026-10-11T00:31:51.816Z"
  pipeline: 0.2.0
  prompts: {}
  input_hash: 65dd027531e1b5cad175b0b55708fa1f58a0f3623ef04cf4411a3b3d155a7dca
evidence:
  - kind: code
    url: https://github.com/microsoft/BCApps/blob/ea08af5ef2d6a9b5c5af4a029288abbe2c883220/src/System%20Application/App/Retention%20Policy/src/Apply%20Retention%20Policy/ApplyRetentionPolicy.Codeunit.al
    title: src/System Application/App/Retention Policy/src/Apply Retention Policy/ApplyRetentionPolicy.Codeunit.al (releases/29.x)
    date: null
    commit: ea08af5ef2d6a9b5c5af4a029288abbe2c883220
    t: null
    quote: null
links:
  learn: []
  objects: []
  features: []
  topics: []
  localizations: []
  videos: []
  posts: []
  guidelines: []
object_type: codeunit
object_id: 3910
name: Apply Retention Policy
namespace: System.DataAdministration
app: System Application
extends: null
first_version: "23"
last_version: "30"
present_in:
  - "23"
  - "24"
  - "25"
  - "26"
  - "27"
  - "28"
  - "29"
  - "30"
changed_in:
  - "28"
source_major: "29"
obsolete: null
countries: []
ms_search_form_ids: []
counts:
  fields: 0
  procedures: 11
  events: 3
  subscribers: 0
relations:
  out: 0
  referenced_by: 0
  pages: 0
  extended_by: 0
  event_subscribers: 9
  calls: 1
  called_by: 5
  implements: 0
---

# Codeunit 3910 "Apply Retention Policy"

> Codeunit 3910 "Apply Retention Policy" in System Application (System.DataAdministration). 8 public procedures, 3 events. Present since at least BC23, still in BC30, changed in BC28.

System Application · System.DataAdministration · BC23-30 · [source at ea08af5e](https://github.com/microsoft/BCApps/blob/ea08af5ef2d6a9b5c5af4a029288abbe2c883220/src/System%20Application/App/Retention%20Policy/src/Apply%20Retention%20Policy/ApplyRetentionPolicy.Codeunit.al) · facts from BC29

## Properties

| Property | Value |
|---|---|
| Access | Public |

## Events published

- `OnApplyRetentionPolicyRecordLimitExceeded(CurrTableId: Integer; NumberOfRecordsRemainingToBeDeleted: Integer; ApplyAllRetentionPolicies: Boolean; UserInvokedRun: Boolean; var Handled: Boolean)` (integration): This event is raised once the maximum number of records which can be deleted in a single run is reached. The limit is defined internally and cannot be changed. The event can be used to schedule a new run to delete the remaining records.
  - subscribers: [Codeunit 3997 "Retention Policy JQ"](../codeunit/3997.md) ScheduleJobQueueEntryOnApplyRetentionPolicyRecordLimitExceeded
- `OnApplyRetentionPolicyIndirectPermissionRequired(var RecRef: RecordRef; var Handled: Boolean)` (integration)
  - subscribers: [Codeunit 1598 "Email Logs Delete"](../codeunit/1598.md) DeleteRecordsWithIndirectPermissionsOnApplyRetentionPolicyIndirectPermissionRequired, [Codeunit 1930 "Performance Profiler Delete"](../codeunit/1930.md) DeleteRecordsWithIndirectPermissionsOnApplyRetentionPolicyIndirectPermissionRequired, [Codeunit 30274 "Shpfy Log Entries Delete"](../codeunit/30274.md) DeleteRecordsWithIndirectPermissionsOnApplyRetentionPolicyIndirectPermissionRequired, [Codeunit 3913 "Retention Policy Logs Delete"](../codeunit/3913.md) DeleteRecordsWithIndirectPermissionsOnApplyRetentionPolicyIndirectPermissionRequired, [Codeunit 3995 "Base Application Logs Delete"](../codeunit/3995.md) DeleteRecordsWithIndirectPermissionsOnApplyRetentionPolicyIndirectPermissionRequired, [Codeunit 6450 "Serv. Integration Mgt."](../codeunit/6450.md) DeleteRecordsWithIndirectPermissionsOnApplyRetentionPolicyIndirectPermissionRequired
- `OnTruncateRecordsIndirectPermissionRequired(var RecRef: RecordRef; var Handled: Boolean)` (integration)
  - subscribers: [Codeunit 3921 "Retention Policy Logs Truncate"](../codeunit/3921.md) TruncateRecordsWithIndirectPermissionsOnTruncateRecordsIndirectPermissionRequired, [Codeunit 3993 "Base Application Logs Truncate"](../codeunit/3993.md) TruncateRecordsWithIndirectPermissionsOnTruncateRecordsIndirectPermissionRequired

## Procedures

- `ApplyRetentionPolicy(UserInvokedRun: Boolean)`: Applies all enabled, non-manual retention polices. This will delete records according to the settings defined in the Retention Policy Setup table.
- `ApplyRetentionPolicy(RetentionPolicySetup: Record "Retention Policy Setup"; UserInvokedRun: Boolean)`: Applies the given Retention Policy. This will delete records according to the settings defined in the Retention Policy Setup table.
- `GetExpiredRecordCount(RetentionPolicySetup: Record "Retention Policy Setup"): Integer`: Returns the number of expired records for the given Retention Policy Setup record. These records would be deleted if the Retention Policy was applied.
- `GetExpiredRecordCount(RetentionPolicySetup: Record "Retention Policy Setup"; var ExpiredRecordExpirationDate: Date): Integer`: Returns the number of expired records for the given Retention Policy Setup record. These records would be deleted if the Retention Policy was applied.
- `SetWhereOlderExpirationDateFilter(DateFieldNo: Integer; ExpirationDate: Date; var RecordRef: RecordRef; FilterGroup: Integer; NullDateReplacementValue: Date)`: This method places a filter on the record reference where records are older than the ExpirationDate. The filter excludes any record where the date field specified in DateFieldNo has no value.
- `SetWhereNewerExpirationDateFilter(DateFieldNo: Integer; ExpirationDate: Date; var RecordRef: RecordRef; FilterGroup: Integer; NullDateReplacementValue: Date)`: This method places a filter on the record reference where records are newer than the ExpirationDate. The filter excludes any record where the date field specified in DateFieldNo has no value.
- `SetSingleDateExpirationDateFilter(DateFieldNo: Integer; ExpirationDate: Date; var RecordRef: RecordRef; FilterGroup: Integer; NullDateReplacementValue: Date)`: This method places a filter on the record reference where records are expired one day at the expiration date. The filter excludes any record where the date field specified in DateFieldNo has no value.
- `TruncateTableRecords(RetentionPolicySetup: Record "Retention Policy Setup")`: Truncates all records in the table specified by the retention policy setup.

## Triggers

OnRun

## Calls

From the extracted call graph of BC29 (graphify-al on the snapshot checkout): calls whose target is known from a declared type or an `Object::"Name"` argument. Interface dispatch and calls through events are not counted, so the list is not complete.

- [Codeunit 3904 "Apply Retention Policy Impl."](../codeunit/3904.md) (7 calls: `ApplyRetentionPolicy → ApplyRetentionPolicy`, `GetExpiredRecordCount → GetExpiredRecordCount`, `OnRun → (object)`, …)

## Called by

- [Codeunit 3904 "Apply Retention Policy Impl."](../codeunit/3904.md) (3 calls: `DeleteExpiredRecords → OnApplyRetentionPolicyIndirectPermissionRequired`, `RaiseRecordLimitExceededEvent → OnApplyRetentionPolicyRecordLimitExceeded`, `TruncateTableRecords → OnTruncateRecordsIndirectPermissionRequired`)
- [Codeunit 3915 "Reten. Pol. Filtering Impl."](../codeunit/3915.md) (3 calls: `ApplyRetentionPolicyAllRecordFilters → SetWhereOlderExpirationDateFilter`, `SetMarksOnRecordRef → SetSingleDateExpirationDateFilter`, `SetMarksOnRecordRef → SetWhereNewerExpirationDateFilter`)
- [Codeunit 3994 "Reten. Pol. Doc. Arch. Fltrng."](../codeunit/3994.md) (3 calls: `SetMarksOnRecordRef → SetSingleDateExpirationDateFilter`, `SetMarksOnRecordRef → SetWhereNewerExpirationDateFilter`, `SetMarksOnRecordRef → SetWhereOlderExpirationDateFilter`)
- [Codeunit 3911 "PBT Expired Record Count"](../codeunit/3911.md) (1 call: `OnRun → GetExpiredRecordCount`)
- [Codeunit 3997 "Retention Policy JQ"](../codeunit/3997.md) (1 call: `OnRun → (object)`)

## Across versions

- Present in: BC23-30
- Changed (declaration) in: BC28

Source: AL metadata extracted from the code (names, ids, signatures, properties); no code bodies (D10).

## Ask your agent

Procedure bodies are not stored here (D10). The call sections above are our own, per object, from the BC29 call graph. For a procedure body or the calls of one procedure, ask bc-code-atlas (external, by Stefan Maron, MIT; default corpus w1-28), which the bc-observatory plugin connects: `bcatlas_resolve_node(object_type: "codeunit", object_name: "Apply Retention Policy")`, then `bcatlas_get_procedure_body` or `bcatlas_get_neighbors` on the returned id.
