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.
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:
- The before delete trigger fires.
- 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.
- The after delete trigger fires.
- The system does the specific updates required for the master record. Normal update triggers apply.