0

In regards to @sfdcfox response to the solution on following thread Batch merging via Apex?

Sorry to invoke this old post but I have a question about Merge_From__c lookup field on the custom object. This will only allow to select one record to merge. If there are two records to merge into master, should I create another record in the Merge_Record__c object? Record1 :Merge_From__c = acc2, Merge_To__c = acc1 Record1 :Merge_From__c = acc3, Merge_To__c = acc1

When I run the batch, the same master might be in the batch twice. Would this cause any issue?

Also, if there are 1000 records to merge, does that mean create 1000 records in Merge_Record__c object?

If yes, what would be the best way to create 1000 records without having to manually sift through the 2000 records?

Thank you !

2 Answers 2

1

If there are two records to merge into master, should I create another record in the Merge_Record__c object? Record1 :Merge_From__c = acc2, Merge_To__c = acc1 Record1 :Merge_From__c = acc3, Merge_To__c = acc1

YES, an additional field for the 3rd merge source record makes sense

When I run the batch, the same master might be in the batch twice. Would this cause any issue?

Transform the list of Merge_Record__c into a set within the transaction execute() scope. That will deal with intraTransaction dups

Extra-transaction dups (across execute()s) - you will need to verify the merge source recs still exist before trying the merge verb

Also, if there are 1000 records to merge, does that mean create 1000 records in Merge_Record__c object?

YES

If yes, what would be the best way to create 1000 records without having to manually sift through the 2000 records?

This is application dependent- you might need to write a script in advance to build these or use excel + dataloader

1
  • Thanks @cropredy for the detailed responses to each question.
    – user4947
    Feb 16, 2019 at 2:58
0

That was an old-school solution to this problem (nearly four years ago!). A modern implementation would use DuplicateRecordSet from Duplicate Rules; let the system match records based on criteria you specify, then modify the batch process to query these records and merge them.

As far as having a single master with multiple duplicates, this should pose no threat to the process; once a record is locked by a transaction, it remains so for the entire transaction. You simply need to remember to limit your DML statements so they won't trip over governor limits (e.g. specify a batch size no larger than the number of expected DML operations per merge operation). If you do run in to governor limits, lower the batch size until it no longer errors.

1
  • Thank you @sfdcfox . I truly appreciate your explanation.
    – user4947
    Feb 16, 2019 at 2:57

You must log in to answer this question.