You need to sign in to do that
Don't have an account?
Goran K.
delete orphaned files
Hi,
I need to periodically delete orphaned files with a Scheduled Flow. Ie. files that don't have a ContentDocumentLink pointing to either Contact, Account, Case, Opportunity.
I am having problem with formulating the query that can be used for this purpose.
Any ides anyone?
-Goran
We've offered this as a service for a while. We build a small app that we used to help perform the analaysis for dealing with the retroactive data... https://sproketlogic.com/dealing-with-files-orphaned-files/
All Answers
Thanks,
Yes
So due to the GDPR rules in Europe, we are required to delete all data about the users when they request it.
What usually happens is that contact with its account, case, interests and opportunity gets deleted manually by our helpdesk employees.
The files which have ContentDocumentLink pointing to these objects are not deleted automatically so we want to be able to locate those files and remove them from Salesforce org.
In other words, we want to be able to find the orphaned files if they no longer have a pointer to either contact, case, oppty, interest.
Our guess is that means to delete ContentDocument with its ContentVersion and ContentDocumentLink.
I noticed that when a parent object is deleted that ContentDocument PublishStatus switch from 'P' to 'R' and FirstPublishLocation.Type = 'User'. So if a files was related to a Contact first, after Contact gets deleted it gets related to the User. User is still Owner but the FirstPublishLocation changes.
This query will return ContentVersion with the two filters:
SELECT Id, Title, FileExtension, PublishStatus , Owner.Name, CreatedDate, FirstPublishLocationId, FirstPublishLocation.Type
FROM ContentVersion
WHERE PublishStatus = 'R' AND FirstPublishLocation.Type = 'User'
So I wish to find out if this is enough to filter out 'orphaned' files. And how to find related ContentDocuments and ContentDocumentLinks to delete those too.
I hope it can be done with a Flow, but we can also use Batch Apex.
Thanks.
-Goran
We've offered this as a service for a while. We build a small app that we used to help perform the analaysis for dealing with the retroactive data... https://sproketlogic.com/dealing-with-files-orphaned-files/