3

When two contacts are merged, does the Non-Master Record Id get added to a list somewhere? It seems like it should, to

  1. ensure that Id does not get used again,
  2. redirect that Id to the Id of the Master Record, or
  3. give one the ability to handle systems outside of SalesForce that store a reference to the Id of the Non-Master Record after a merge.

From what I can tell, the Non-Master Record just gets added to the recycle bin, where it is deleted in two weeks. Is this the whole story?

3

The loser(s) get the winner's Id written into MasterRecordId. Check Contact for example. Nothing is saved on winner record though so when the losers eventually get wiped from recycle bin the Id is really gone.(*)

If you want to persist such info - you have to do it yourself. SF doesn't save anything on master (*) because what do you think would happen when you merge 10 contacts into 1? If you want to save the values anyway - use a text field and not lookups ;)

Id won't be reused for sure. "Ensuring" is done internally.

If you need to notify external systems - it's your job again. Triggers will fire on merge, send your callouts from them for example?

If you're concerned - either track them with your own code or "soft delete" your records (tick some checkbox that will cause them to be assigned to user that's outside Role hierarchy, excluded in criteria-based sharing rules etc.). Users with "View all data" will still see them but otherwise they'll disappear from reports for example.


(*) Actually there's something that's retained for you out of the box - in the field history tracking tables. We can see the name of the merged record but queries won't show the id. So in your external systems scenarios you probably could only "identify suspect winners" that way:

SELECT Id, Field, NewValue, OldValue
FROM AccountHistory
WHERE Field = 'accountMerged'
LIMIT 10

Notes:

  1. The query result renders incorrectly in workbench.developerforce.com. Try with the Developer Console if you're getting funny results.
  2. If you plan to build your logic around history trackers be aware that it's royal paint to unit test the code - histories are written to tables only after successful commit.
  3. ... and they can be truncated / shortened when you refresh a sandbox.
2
  • 1
    You can also detect the record's deletion for 30 days using the replication API, even if it is hard deleted sooner. Of course, you can't retrieve the MasterRecordId after it's hard deleted. That's the purpose of the getDeleted API. If you don't sync at least once every 30 days, you have to perform a full re-sync.
    – sfdcfox
    Jan 15 '14 at 20:59
  • Ahh, I forgot about the getDeleted(), thx!
    – eyescream
    Jan 15 '14 at 21:04

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.