Input & Output

Merge records (List of SObjects) and set Master

The doMerge method merges multiple Salesforce records into a single master record, allowing you to explicitly specify which record should be the master. The method follows the Plauti Deduplicate Merge Rules and returns a boolean to indicate success or failure.

Method Signature

Method Name: doMerge

Boolean doMerge(List<SObject> objectList, SObject masterObject)

Parameters

TypeVariableDescription
List<SObject>objectListA list of Salesforce objects to be merged.
SObjectmasterObjectA Salesforce object representing the master record. Must include at least the Id of the master record. Fields set on this object will be updated in the master record.

📘

Ensure that all fields with custom merge rules (i.e., rules other than “Master Record Rule”) are included in the query performed within the doMerge method. The doMerge method relies on these fields to apply the defined custom merge rules. If required fields are missing in the data processed by doMerge, the method will fail, as it cannot execute the custom merge logic without the necessary field values.

Output

  • true: The merge was successful.
  • false: The merge failed.

Apex Example

This snippet queries duplicate Contact records, specifies a master Contact with optional field updates, and merges them using the Plauti Deduplicate API. It logs the queried contacts, sets the master record, initiates the merge, and outputs whether the merge was successful.

// Query the records you want to merge
List<Contact> duplicateContacts = [
    SELECT Id, Name, Email, LastModifiedDate
    FROM Contact
    WHERE Id IN ('003J8000007jigQIAQ', '003J8000007jigRIAQ')
];
System.debug('Queried duplicate contacts: ' + duplicateContacts);

// Specify the master record and update specific fields
final Contact masterContact = new Contact(
    Id = '003J8000007jigQIAQ',
    Phone = '123-456-7890' // Example optional field update
);
System.debug('Master Contact specified: ' + masterContact);

// Initialize the Duplicate Check API
final dupcheck.dc3Api dc3Api = new dupcheck.dc3Api();
System.debug('Duplicate Check API initialized.');

// Execute the merge using the Duplicate Check API
System.debug('Executing merge operation with specified master record...');
Boolean isMerged = dc3Api.doMerge(duplicateContacts, masterContact);
System.debug('Merge operation completed. Merge result: ' + isMerged);

// Output result with conditional feedback
if (isMerged) {
    System.debug('Merge was successful.');
    // Add any post-merge actions here if required
} else {
    System.debug('Merge failed.');
}