Delete contact but keep related records - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
Internal ITInternal IT 

Delete contact but keep related records

Hi all

I knw it's recommended to not delete Contacts but we have users who are determined to rid their lists of old/outdated contacts.

Does anyone have a solution that allows for Contacts to be deleted but for related records(Activities, Notes, etc) to be saved and still attached to the Account?  Or perhaps some transferred to some "dummy" Contact that is used for this purpose?

All help appreciated!

Bill
Best Answer chosen by Internal IT
Krishna DadiKrishna Dadi
Hi Bill,
Yes WhatId is record id which you want to related to, i guess in your case it is Account record, whoId is usually either contact or Lead  record, so you have to null out .

Since the Note is stored in 'Content,' we need to query  the 'Content Document Link' table in order to do this.

select id, ContentDocumentId, LinkedEntityId from ContentDocumentLink where LinkedEntityId  in (contactids)

then change the LinkedEntityId  from contact to accountid
sample code:
for(ContentDocumentLink  cdl: cdList) {
cdl.LinkedEntityId = acc.Id; //replace contactId with accountId
//cdl.ContentDocumentId = NotesId;
cdl.shareType = 'V';
}
update cdList;

 

https://help.salesforce.com/articleView?id=000339316&language=en_US&type=1&mode=1


 

All Answers

Krishna DadiKrishna Dadi
HI Internal IT ,
Download the Activities of the contacts and change RelatedToId  from Contact to Account or any other contact and upload it again.

You can do this with 1. Data Loader 2. WorkBench  3. DataLoader.IO  
Internal ITInternal IT
Thanks for your reply.

I was thinking of something that happened at the point of contact deletion.  So I guess some trigger code to do as you suggest.  Plus, would that work on Notes?

B
Krishna DadiKrishna Dadi
HI Internal IT,
You definitely can attach the Activities and Notes of Contact to the respective account on the deletion of contact records with Triggers.

 
Alex YouroukelisAlex Youroukelis

Hi

You are in luck.... a new Winter '21 feature will allow you to run a flow before a record is deleted:

https://releasenotes.docs.salesforce.com/en-us/winter21/release-notes/rn_forcecom_flow_fbuilder_trigger_flow.htm?edition=&impact=

So you can ensure the RelatedToId is updated to Account befpre the Contact is deleted

 

Internal ITInternal IT
Thanka Alex.

Krishna, thanks for the assurance. Is it aklways the "WhatID" that I need to update?  And just null out the WhoId?  It seems Notes dont follow that principle?

BIll
Krishna DadiKrishna Dadi
Hi Bill,
Yes WhatId is record id which you want to related to, i guess in your case it is Account record, whoId is usually either contact or Lead  record, so you have to null out .

Since the Note is stored in 'Content,' we need to query  the 'Content Document Link' table in order to do this.

select id, ContentDocumentId, LinkedEntityId from ContentDocumentLink where LinkedEntityId  in (contactids)

then change the LinkedEntityId  from contact to accountid
sample code:
for(ContentDocumentLink  cdl: cdList) {
cdl.LinkedEntityId = acc.Id; //replace contactId with accountId
//cdl.ContentDocumentId = NotesId;
cdl.shareType = 'V';
}
update cdList;

 

https://help.salesforce.com/articleView?id=000339316&language=en_US&type=1&mode=1


 
This was selected as the best answer
Krishna DadiKrishna Dadi
HI Bill,
R u able to resolve the issue, let us know if you have any questions, Otherwise please close by selecting answer which helped you most to resolve the issue as the best answer ,