0

I need to update some fields in my lead record only when the merge process runs through "Find Duplicate" button and not on normal update operation. Can it be achieved through trigger or do I need to create a custom button that carry out the merge functionality and then use some checkbox to update the record.

0

You can determine when a merge DML operation occurs from triggers, but not necessarily whether they're from the "Find/View Duplicates" button. This answer assumes you don't need to differentiate between other merge operations and "Find/View Duplicates" merges.

A merge involves the deletion of the losing record followed by the update of the winning record. From the after delete trigger of the losing Lead record you can check for the existence of a value in the MasterRecordId field to determine whether the deletion is the result of a merge opration.

Per the Apex documentation:

The following is the order of events when a merge occurs:

  1. The before delete trigger fires.
  2. The system deletes the necessary records due to the merge, assigns new parent records to the child records, and sets the MasterRecordId field on the deleted records.
  3. The after delete trigger fires.
  4. The system does the specific updates required for the master record. Normal update triggers apply.

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.