douglascayers / sfdc-convert-attachments-to-chatter-files

πŸ“Ž Easily migrate your Attachments to Salesforce Files.
https://douglascayers.com/2015/10/10/salesforce-convert-attachments-to-chatter-files/
BSD 3-Clause "New" or "Revised" License
73 stars 29 forks source link

Creating duplicate files for already converted files #19

Closed gribis closed 7 years ago

gribis commented 7 years ago

When I am running the batch process multiple times for the same parent records, it appears that the duplicate prevention method (filterAlreadyConvertedAttachmentIds) is not catching already converted files. So I did some digging, trying to replicate what the dup-prevention method does: Retrieve ContentVersion records for already converted attachments. SELECT original_record_id__c FROM ContentVersion WHERE original_record_id__c='{attachmentId}’ Oddly enough, this query does not return any records for known converted attachment Ids. However, if I include the ContentVersion.Id or the ContentDocumentId in the same query, the record is returned. SELECT original_record_id__c FROM ContentVersion WHERE original_record_id__c='{attachmentId}’ AND Id='{ContentVersionId}' The settings are as follows:

While I have attempted to remove files upon completion, that has not worked thus far either, which may be related to the issue. I am running the process as an admin with audit data update privileges.

douglascayers commented 7 years ago

Hi @gribis,

Thanks for the detailed information, this is quite helpful! Do you notice this problem if you run the conversion scoped to a single parent record? Do you happen to notice the issue related to specific parent records or parent object types? Anything you notice about the owners of the attachments? Have a Role, don't have a Role? Salesforce license type of the owners?

I'm wondering if there's an edge case to uncover...

Thanks

douglascayers commented 7 years ago

Confirmed that we're running into a special access rule with ContentVersion records. Despite being an administrator with Modify All Data permission, if the current user does not own the record then they do not find any results when simply querying SELECT id FROM ContentVersion WHERE original_record_id__c = :attachment.id ]

Researching what other options we have; I'd hate to have to create a custom object for tracking whether attachment has been converted or not. Just feels icky to me. We'll see...

douglascayers commented 7 years ago

Good news, I think I've solved it by instead querying ContentDocumentLink object! I'll do some further testing soon and hopefully have new release available this week.

Thanks

gribis commented 7 years ago

I saw your finding and will attempt to integrate with my version of the code. Nice work on tracking this down. Best, Stefan

On Apr 10, 2017, at 11:32 PM, Doug Ayers notifications@github.com wrote:

Closed #19 via 10d9ea0.

β€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.