Skip to content

Identifying Duplicates

GitHub Action edited this page Nov 11, 2025 · 1 revision

Performing duplicate detection using apex-database-layer is simple!

DatabaseLayer.Duplicates wraps the standard Datacloud.FindDuplicates class, providing a mockable interface for duplicate detection operations.

To leverage the framework, use the DatabaseLayer.Duplicates equivalent of Datacloud duplicate detection methods:

// Don't use the standard Datacloud method:
List<Datacloud.FindDuplicatesResult> results = Datacloud.FindDuplicates.findDuplicates(records);
// Use the DatabaseLayer.Duplicates equivalent:
List<Duplicates.FindDuplicatesResult> results = DatabaseLayer.Duplicates.findDuplicates(records);

Why?

We recommend using DatabaseLayer.Duplicates instead of Datacloud.FindDuplicates methods across your entire codebase. This practice has the following benefits:

  • Easily mock duplicate detection operations in tests, usually with just a few lines of code!
  • Test duplicate rule logic without relying on actual duplicate rules in your org
  • Simulate various duplicate detection scenarios including matches, errors, and field differences

apex-database-layer

Home

Core Concepts

Reference Guide

Migration Gudes

Clone this wiki locally