Start an Auto Convert job from Apex

The dc3ConvertBatch process lets you trigger the Auto Convert 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 Convert in its options. You point it at the parent search job, set a score threshold, and it converts every duplicate Lead in that job that meets the threshold into the matching Account or Contact.

Auto Convert is the lead-conversion counterpart of Auto Merge: where merge combines duplicate records of the same object, convert turns duplicate Leads into existing Accounts and Contacts. The two follow the same pattern, so if you have read the Auto Merge article this will look familiar.

📘

A completed cross-object Lead search job is required first

Conversion turns a Lead into a matching Account or Contact, so the parent must be a cross-object search job that matches the Lead object (00Q) against the Account object (001) or the Contact object (003). A parent dupcheck__dcJob__c of type search with those objects must already exist. See Start a Plauti deduplicate job from Apex to create one from Apex.

🚧

The Batch Convert feature must be licensed

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

Key Points

  • Runs against an existing Lead 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 convert, linked to the parent search job through dupcheck__parent__c.
  • Converts only the duplicate groups whose match score is greater than or equal to dupcheck__autoProcessThreshold__c.
  • Executes the conversion through the dupcheck.dc3ConvertBatch batch class, so it scales to large jobs within Salesforce governor limits.
  • The converted-record owner and the Lead status to apply are passed directly to the batch class, not stored on the job record.
  • Updates the convert job record with the Apex job Id, and marks the parent search job's auto-process type as CONVERT, so the operation is traceable from the Plauti Deduplicate UI.
FieldTypeDescription
dupcheck__name__cStringA custom name for the convert job, used as a label to identify it.
dupcheck__type__cStringMust be set to 'convert', indicating that this job performs a convert operation. Do not change.
dupcheck__sourceObject__cStringThe source object. Must match the parent search job's source object — the Lead object (00Q) for conversion.
dupcheck__matchObject__cStringThe match object. Must match the parent search job's match object — the Account object (001) or the Contact object (003).
dupcheck__parent__cIdThe ID of the parent search job whose duplicate results will be converted.
dupcheck__autoProcessThreshold__cIntegerThe minimum match score percentage a duplicate group must reach to be converted.
dupcheck__autoProcessType__cStringMust be set to 'CONVERT'. Do not change.

Apex Example

// The Id of the parent Lead search job whose duplicates you want to convert.
// 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 convert
String convertOwner = 'ACCOUNT';   // Owner of the converted records (see below)
String convertStatus = 'Closed - Converted'; // A Lead status where IsConverted = true (pass null to use the default)

Savepoint savepoint = Database.setSavepoint();
try {
    // Create a new DC Job record for the convert operation
    dupcheck__dcJob__c convertJobData = new dupcheck__dcJob__c(
        dupcheck__name__c = 'Convert if score is greater than or equal to ' + String.valueOf(threshold) + '%',
        dupcheck__type__c = 'convert',           // Constant value (do not change)
        dupcheck__sourceObject__c = '00Q',        // Lead — must match the source object of the search job
        dupcheck__matchObject__c = '001',         // Account — 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 = 'CONVERT'  // Constant value (do not change)
    );

    // Insert the convert job definition
    insert convertJobData;

    // Start the convert batch process with a batch size of 1
    Id apexJobId = Database.executeBatch(
        new dupcheck.dc3ConvertBatch(searchJobId, threshold, convertOwner, convertStatus, convertJobData.Id),
        1
    );

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

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

The dc3ConvertBatch constructor takes five arguments, in this order:

  1. searchJobId — the Id of the parent search job to convert.
  2. threshold — the minimum match score percentage.
  3. convertOwner — who owns the converted Account/Contact (see the table below).
  4. convertStatus — the Lead status applied on conversion.
  5. convertJobData.Id — the Id of the child convert job you just created.

Convert owner

The convertOwner argument mirrors the Owner option in the Auto Convert dialog. When left blank it defaults to LEAD.

ValueResult
LEADThe converted records keep the Lead's owner.
ACCOUNTThe converted records take the matching Account's owner.
CONTACTThe converted records take the matching Contact's owner.
A User IdThe converted records are assigned to that specific user.

Convert status

The convertStatus argument must be a Lead Status with IsConverted = true (for example Closed - Converted). If left blank, the process falls back to the converted status configured in Plauti Deduplicate, and otherwise to the org's default converted Lead status.

Recommendations

  • Use a batch size of 1. Each conversion touches the Lead and its matching Account and Contact, so a small batch size keeps every transaction comfortably within governor limits. This matches the batch size Plauti Deduplicate uses internally for Auto Convert.
  • Wrap the setup in a savepoint and try/catch, as shown above, so the job records succeed or roll back together and a partial failure cannot leave an orphaned convert job.
  • Set the threshold deliberately. Only duplicate groups scoring at or above the threshold are converted; the rest stay in the job untouched.

When to convert specific records instead

If you do not want a batch-style run over a whole job — for example, you want to convert a known set of Leads under custom business logic — use the direct merge and convert methods instead. See Merge Methods.