Using the Merge Interface
Merge plugin
This article explains how to extend Plauti Deduplicate merge functionality by implementing the Merge Interface. You can use this interface to run custom logic before a merge is executed, after a merge has completed, or when a merge fails—based on the context provided by the system.
Overview
The Merge Interface allows you to insert custom logic into the duplicate record merge process. The trigger is a merge initiated by the Plauti Deduplicate tool (Either a manual merge, quick merge or auto merge).
Implementation
To implement the Merge Interface, create an Apex class that implements the dupcheck.dc3Plugin.InterfaceMerge
interface. The primary methods to implement are:
beforeMerge(String objectPrefix, Sobject masterRecord, List<Sobject> mergedRecordList)
mergeFailed(String objectPrefix, Sobject masterRecord, Set<Id> mergedRecordIds, dupcheck.dc3Exception.MergeException exceptionData)
afterMerge(String objectPrefix, Sobject masterRecord, Set<Id> mergedRecordIds)
Step 1. Create Apex Class
Ensure your class is declared as global
so that it can be referenced by the Plauti Deduplicate framework.
Step 2. Implement `beforeMerge` Method
objectPrefix
: The 3-character object indicator (e.g., '00Q' for Leads).masterRecord
: The record that will remain as the master after the merge. Its field values can be modified before the merge.mergedRecordList
: A list of records that are to be merged into the master record.
Step 3. Implement `mergeFailed` Method
objectPrefix
: The 3-character object indicator (e.g., '00Q' for Leads).masterRecord
: The record that should have remained as the master after the merge.mergedRecordIds
: A set of IDs corresponding to the records that were planned to be merged into the master record.exceptionData
: The exception thrown by Salesforce that explains why the merge failed.
Step 4. Implement `afterMerge` Method
objectPrefix
: The 3-character object indicator (e.g., '00Q' for Leads).masterRecord
: The record that remains after a successful merge, now containing consolidated data.mergedRecordIds
: A set of IDs for the records that were merged into the master record.
Step 5. Reference the Plugin in DC Settings
In your Salesforce org, navigate to the Deduplicate Setup page, then open the DC Settings section.
Under the "Merge Plugin" field, enter the fully-qualified name of your custom Apex class (e.g., DefaultMerge
).
This registration ensures that the Duplicate Check framework uses your implementation during merge operations.
Supported Methods
The following methods help you understand the context in which your merge logic is executed:
Method Name | Description |
---|---|
beforeMerge | Called before the merge operation is executed. Use this method to prepare the master record or modify incoming data. |
mergeFailed | Called when the merge operation fails. Use this method to log errors, handle exceptions, or trigger corrective actions. |
afterMerge | Called after a successful merge. Use this method to perform any necessary cleanup or to update related records. |
flowchart LR A[Merge Initiated] --> B[**Call beforeMerge**] B --> C{Merge Executed} C -- Successful --> D[**Call afterMerge**] C -- Failed --> E[**Call mergeFailed**] D --> F[Merge Process Completed] E --> F
Each of these methods provides critical context:
objectPrefix
helps identify the type of record (for example, Leads have the prefix '00Q').masterRecord
is the record that is intended to be the final, consolidated record.mergedRecordList
/mergedRecordIds
represents the records that are being merged into the master.exceptionData
(inmergeFailed
) provides details about why a merge operation did not succeed.
By implementing and enabling this Merge Plugin in your Deduplicate Setup, you gain granular control over the merge process for duplicate records.
Optional: Stopping a Merge
To stop a merge using the Merge Interface, implement your logic inside the beforeMerge
method. This method is executed before the merge takes place. You can validate the records involved, such as querying fields or applying business rules, and if any condition is met that should prevent the merge, throw a custom exception. Throwing an exception will immediately cancel the merge, show an error to the user, and roll back any pending changes. This ensures that data integrity is preserved when certain conditions should block merging.
For a code example, see the Examples & Use Cases article.
Optional: Using NoProcessException
for Alternative Merge Logic
NoProcessException
for Alternative Merge LogicNoProcessException
is a special exception provided by the Plauti Deduplicate framework to bypass the merge process without causing an error. When you throw this exception inside beforeMerge
, the framework treats the merge as successful, but skips the actual merge logic, no records are merged or deleted. This allows you to run custom logic instead of merging, such as creating hierarchies, setting relationships, or triggering workflows.
Important: Unlike a regular exception, NoProcessException
does not stop the process with an error. It signals that you’ve handled the operation intentionally, and Plauti should skip the merge but continue the process flow. Use it when you want an alternate outcome instead of a failure.
For implementation examples, see the Examples & Use Cases article.
Updated 7 days ago