0

I have a custom object A and a custom object B.

Custom object A is the parent object.

Custom object B is the child object.

The relationship between custom object A and custo object B is a master-detail relationship.

The issue I have is in custom object A I have multiple duplicated custom object B records.

I'm looking for a way to mass merge all duplicated custom object B records.

Please advise is there a way to mass merge dulplicated records in a custom object?

1

Salesforce offers programmatic merge support only for Lead, Contact, and Account records using the merge DML operation:

Only leads, contacts, and accounts can be merged

To merge custom objects, you'll need to define the merge semantics yourself, and you can't, unfortunately, take advantage of the native merge operation's reparenting support.

To do this whole objective, you'd have to

  • Define logic to locate duplicate records.
  • Define logic for selecting a "winning" and "losing" records.
  • Define logic for how field values from the source objects are combined, or which records' values survive.
    • I'm assuming your duplicates all share a parent and don't have their own children; otherwise, you have some additional reparenting considerations.
  • Write code to merge those field values, delete losing records, and update winning records.
  • Write batch and/or scheduled Apex to perform this entire operation on a regular basis.

As an alternative to a not-insubstantial project, you might consider one of the many available third-party duplicate management products, at least some of which (I won't name names here because I'm not a fan of the vendor involved) offer bulk merge of custom objects out of the box.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.