You need to sign in to do that
Don't have an account?
Merge Statements in trigger :
Hi All,
Merge Statements in trigger :
1 > What is Merge Statement ?
2 > Why use this merge statement?
3 > When use this merge statement?
Give me one example.
Allready i searched in google. But i am not getting about the winning record and losing record.
can any one explain ?
Thanks in advance
Thulasi
Merge Statements in trigger :
1 > What is Merge Statement ?
2 > Why use this merge statement?
3 > When use this merge statement?
Give me one example.
Allready i searched in google. But i am not getting about the winning record and losing record.
can any one explain ?
Thanks in advance
Thulasi
- merge is a DML like insert or update but this can only be executed with some Standard objects, Accounts, Contact and Leads. You can merge up to 3 records in one.
- This merge statement is used in order to remove duplicate records from your database.
- For instance, you have 2 contacts duplicated associated to the same Account. Then you can merge the info of both contacts and remove one of them.
I found this documentation:- merge() -- https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_merge.htm
- example -- https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_dml_examples_merge.htm
- merge duplicate contacts -- https://help.salesforce.com/apex/HTViewHelpDoc?id=contacts_merge.htm&language=nl (https://help.salesforce.com/apex/HTViewHelpDoc?id=contacts_merge.htm&language=nl)
Hope this helpsThanks you very much.
When you have duplicate lead, contact, or account records in the database, cleaning up your data and consolidating the records might be a good idea. You can merge up to three records of the same sObject type.
Sample code for you:-
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_dml_examples_merge.htm
1 > What is Merge Statement ?
2 > Why use this merge statement?
3 > When use this merge statement?
When you have duplicate lead, contact, or account records in the database, cleaning up your data and consolidating the records might be a good idea. You can merge up to three records of the same sObject type
1) Only leads, contacts, and accounts can be merged
2) You can pass a master record and up to two additional sObject records to a single merge method
3) External ID fields can’t be used with merge
The following example merges two accounts named 'Acme Inc.' and 'Acme' into a single record: https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_merge.htm
Triggers and Merge Statements
Merge events do not fire their own trigger events. Instead, they fire delete and update events as follows:
Deletion of losing records
A single merge operation fires a single delete event for all records that are deleted in the merge. To determine which records were deleted as a result of a merge operation use the MasterRecordId field in Trigger.old. When a record is deleted after losing a merge operation, its MasterRecordId field is set to the ID of the winning record. The MasterRecordId field is only set inafter delete trigger events. If your application requires special handling for deleted records that occur as a result of a merge, you need to use the after delete trigger event.
Update of the winning record
A single merge operation fires a single update event for the winning record only. Any child records that are reparented as a result of the merge operation do not fire triggers.
For example, if two contacts are merged, only the delete and update contact triggers fire. No triggers for records related to the contacts, such as accounts or opportunities, fire.
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 theMasterRecordId 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.