1

We have a checkered history at this company that caused all sorts of bad data. (I wasnt here then!)

  • Person Accounts are enabled. Some of the customers are Person Account records, and some are just Contact records, which makes them "private Contacts".

There ought to be only one record that has any given email address. But there are many duplicates, which we are addressing.

  • The Contact has a unique external-ID custom field (so, the Person Account does too). It is null on many records of each Object, which in itself is OK and has a meaning.
  • A private Contact cannot be placed into an Account, it is a Salesforce limitation.
  • So when the email address of a PA matches that of a Contact, it is the Contact that must be deleted and its data merged into the PA. But the dedupe tool cannot do this when the Contact has a value in the external-id field, because it saves (tries to save) the merged record before it deletes the Contact, and the save fails due to the external-id non-uniqueness.
  • We must not lose the external-id value.

Option 1

  • One bad solution is to save off the external-ID and then erase it, do the merge, and then restore the external-id. This breaks our integrations for however long it takes and risks permanent damage if there is an interruption.

Option 2

Another solution would be to write Apex that

  • 1) stores the value in another field and
  • 2) removes it from the unique field,
  • 3) does the merge, and
  • 4) restores the value into the merged record, all in a single transaction (so it can be rolled back).

Is there a better way? Is the Apex solution safe?

  • I edited this to make it readable – cropredy Oct 11 '19 at 21:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.