function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mahesh reddy 4mahesh reddy 4 

opportunity Merging

Hi, In one application i want to merge the opportunities under the account object. Please share the apex code for this requirement..As soon as possible..Thanks in Advance.
Gaurav KheterpalGaurav Kheterpal
This is NOT possible directly. You can follow this approach to hack around this limitation.


1. You will have to manually copy the information from the duplicate opportunity to the surviving opportunity then delete the duplicate.
2. Use App-Exchange apps as Dupe Blocker / Dupe Catcher / Dupe Eliminator / CRM Fusion tools, etc.
3. If you are / have developer in team, you can program APEX trigger with delete and update events. Order of Execution can be :
  • 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.
If my answer helps resolve your query, please mark it as the 'Best Answer' to benefit others and improve the overall quality of Discussion Forums.