How can I detect what record is the Master
Learn how to retrieve the surviving master record ID before updating and merging duplicate pairs using Delpha's Apex API.
When managing duplicate records, you often need a programmatic way to evaluate a pair of duplicates and determine which record should be preserved (the "Master") and which should be archived or deleted.
Depending on your use case, you can evaluate a single pair of duplicates or process them in bulk.
1. Single Record Processing
Method Overview
The function evaluates two duplicate records against your configured Delpha selection rules to identify the primary master record.
Function Signature
Id masterRecordId = delpha.DDQ_DuplicateApi.getMaster(
'[RecordId1]',
'[RecordId2]',
'[DuplicateSettingId]'
);Parameters
Parameter
Type
Description
RecordId1
String / Id
Salesforce Record ID of the first duplicate.
RecordId2
String / Id
Salesforce Record ID of the second duplicate.
DuplicateSettingId
String / Id
The ID of the Delpha Duplicate Setting containing your selection rules.
Output: Returns the Id of the master record.
Step-by-Step Implementation Guide
Step 1: Select Duplicate Records
Query the duplicate pairs that require processing. This step is required when preparing records for bulk processing.
Step 2: Retrieve the Duplicate Setting ID
Navigate to the Delpha Setup app in Salesforce.
Open the Duplicate Setting rule you wish to apply.
Copy the Record ID directly from the browser URL.
Step 3: Execute getMaster
Call delpha.DDQ_DuplicateApi.getMaster() passing delpha__RecordId__c, delpha__MatchedRecordId__c, and your DuplicateSettingId.
Permissions: The running user must have an active Delpha License and be assigned the Delpha Admin Permission Set Group.
2. Bulk Record Processing
When processing large volumes of duplicate records (for example, in a Scheduled Batch Apex job), you can resolve multiple pairs at once using a bulkified method.
Method Overview: resolve()
Evaluates a list of duplicate pairs and determines the winning master record for each pair in a single bulkified operation.
Signature
Parameters
Parameter
Type
Required
Description
pairs
List<delpha__DDQ_DuplicateRecord__c>
Yes
List of duplicate pair SObjects to evaluate. Every record in the list must have all required fields explicitly queried in SOQL beforehand.
Return Value
Return Type
Description
Map<Id, Resolution>
A map where each key corresponds to a duplicate pair record Id (delpha__DDQ_DuplicateRecord__c.Id), and the value is a Resolution object containing the master record determination result.
Key Behaviors & Exceptions
No Automatic Field Check: The method assumes all required fields are loaded. Omitting any required field from the input records will throw an unhandled
System.SObjectException.No Internal DML or Logging: This method is purely evaluative—it returns calculation results and does not update records in the database or generate error logs internally.
1:1 Mapping: Output guarantees exactly one
Resolutionentry per distinct duplicate pair ID passed in thepairslist.
Step by Step implementation Guide
Prerequisites
To execute this, you will use custom local Apex classes deployed in your Salesforce org to process the duplicate pairs generated by the Delpha managed package.
delpha__DDQ_DuplicateRecord__c: The custom object provided by the Delpha package.DuplicateResolverandResolution: Custom local Apex classes (not provided by Delpha) used to process Delpha's data and return the designated master record.
Code Example
Below is the standard snippet to retrieve unhandled duplicate pairs and resolve them in bulk.
Important Technical Considerations
Required Fields
Field API Name
Data Type
Description
Id
Id
The unique Salesforce Record ID of the delpha__DDQ_DuplicateRecord__c duplicate pair record.
delpha__RecordId__c
Id (Lookup)
The Salesforce Record ID of the primary record in the duplicate pair.
delpha__MatchedRecordId__c
Id (Lookup)
The Salesforce Record ID of the matched candidate record in the duplicate pair.
delpha__IsCrossRecord__c
Boolean
Indicates whether the match is across different SObject types (e.g., Lead vs. Contact) or within the same object type.
delpha__DuplicateSettings__c
Id (Lookup)
The ID of the specific Delpha duplicate setting rules/configuration applied to evaluate this pair.
Omitting any of these 5 fields from your initial SOQL query will result in an unhandled System.SObjectException at runtime when resolve() executes.
The
ResolutionMap The custom method returns aMap<Id, Resolution>where the key is the ID of thedelpha__DDQ_DuplicateRecord__cpair, and the value is aResolutionobject containing the Master ID.Next Steps The provided code evaluates the data, but does not execute any Database changes. You must replace the
System.debug()line with your own Database operations (such asDatabase.mergeor updating status fields) based on your business requirements.
Permissions: The running user must have an active Delpha License and be assigned the Delpha Admin Permission Set Group.
Last updated
Was this helpful?