Start an Auto Merge job from Apex

The dc3MergeBatch process lets you trigger the Auto Merge of an existing Deduplicate search job from Apex. This is the programmatic equivalent of opening a completed (or previously stopped) duplicate job and choosing Start Auto Merge in its options. You point it at the parent search job, set a score threshold, and it merges every duplicate group in that job that meets the threshold.

This is useful when a search job already ran — perhaps as part of a scheduled batch — and you want to merge its results later, conditionally, from your own automation rather than by hand.

📘

A completed search job is required first

Auto Merge runs against the duplicates found by a search job, so a parent dupcheck__dcJob__c of type search must already exist. See Start a Plauti deduplicate job from Apex to create one from Apex.

🚧

The Batch Merge feature must be licensed

Constructing dupcheck.dc3MergeBatch throws a LicenseException ("Feature not licensed or license expired.") when neither the Batch Merge nor Quick Merge feature is available on the org's Plauti Deduplicate license.

Key Points

  • Runs against an existing search job, identified by its dupcheck__dcJob__c record Id — no list of SObjects or record Ids is needed.
  • Creates a child dupcheck__dcJob__c record of type merge, linked to the parent search job through dupcheck__parent__c.
  • Merges only the duplicate groups whose match score is greater than or equal to dupcheck__autoProcessThreshold__c.
  • Executes the merge through the dupcheck.dc3MergeBatch batch class, so it scales to large jobs within Salesforce governor limits.
  • Updates the merge job record with the Apex job Id, and marks the parent search job's auto-process type as MERGE, so the operation is traceable from the Plauti Deduplicate UI.
FieldTypeDescription
dupcheck__name__cStringA custom name for the merge job, used as a label to identify it.
dupcheck__type__cStringMust be set to 'merge', indicating that this job performs a merge operation. Do not change.
dupcheck__sourceObject__cStringThe ID of the source object. Must match the source object of the parent search job.
dupcheck__matchObject__cStringThe ID of the match object. Must match the match object of the parent search job.
dupcheck__parent__cIdThe ID of the parent search job whose duplicate results will be merged.
dupcheck__autoProcessThreshold__cIntegerThe minimum match score percentage a duplicate group must reach to be merged.
dupcheck__autoProcessType__cStringMust be set to 'MERGE'. Do not change.

Apex Example

// The Id of the parent search job whose duplicates you want to merge.
// This is a completed (and possibly previously stopped) dupcheck__dcJob__c of type 'search'.
Id searchJobId = 'a0X...';
Integer threshold = 80; // Minimum match score percentage to merge

Savepoint savepoint = Database.setSavepoint();
try {
    // Create a new DC Job record for the merge operation
    dupcheck__dcJob__c mergeJobData = new dupcheck__dcJob__c(
        dupcheck__name__c = 'Merge if score is greater than or equal to ' + String.valueOf(threshold) + '%',
        dupcheck__type__c = 'merge',           // Constant value (do not change)
        dupcheck__sourceObject__c = '001',      // Must match the source object of the search job
        dupcheck__matchObject__c = '001',       // Must match the match object of the search job
        dupcheck__parent__c = searchJobId,      // Link to the parent search job
        dupcheck__autoProcessThreshold__c = threshold,
        dupcheck__autoProcessType__c = 'MERGE'  // Constant value (do not change)
    );

    // Insert the merge job definition
    insert mergeJobData;

    // Start the merge batch process with a batch size of 1
    Id apexJobId = Database.executeBatch(
        new dupcheck.dc3MergeBatch(searchJobId, threshold, mergeJobData.Id),
        1
    );

    // Update the merge DC Job record with the Apex job ID for tracking purposes
    update new dupcheck__dcJob__c(Id = mergeJobData.Id, dupcheck__apex__c = apexJobId);

    // Mark the parent search job's auto-process type as MERGE
    update new dupcheck__dcJob__c(Id = searchJobId, dupcheck__autoProcessType__c = 'MERGE');
} catch (Exception e) {
    // Roll back the job records so a failure does not leave an orphaned merge job behind
    Database.rollback(savepoint);
    throw e;
}

The dc3MergeBatch constructor takes three arguments, in this order:

  1. searchJobId — the Id of the parent search job to merge.
  2. threshold — the minimum match score percentage.
  3. mergeJobData.Id — the Id of the child merge job you just created.

Recommendations

  • Use a batch size of 1. A single merge can touch many related records across several objects, so a small batch size keeps each transaction comfortably within governor limits. Increase it only after testing with your own data volumes.
  • Wrap the setup in a savepoint and try/catch, as shown above. The DML that creates and links the job records should succeed or roll back together, so a partial failure does not leave an orphaned merge job.
  • Set the threshold deliberately. Only duplicate groups scoring at or above the threshold are merged; the rest stay in the job untouched.

When to merge specific records instead

If you do not want a batch-style run over a whole job — for example, you want to merge a known set of records under custom business logic — use the direct merge methods instead. See Merge Methods, which merge a list of SObjects or record Ids you provide.