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

Failures when CRM Content not enabled #24

Closed jamesmelville closed 6 years ago

jamesmelville commented 7 years ago

If CRM Content is not enabled in the org then the conversion fails. It happens in different ways dependent on the settings:

Users can only view the file but cannot edit it, even if the user can edit the attachment's parent record

The following error occurs:

Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_OR_READONLY, You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessar

and

Users inherit view or edit access to the file based on their view or edit access to the attachment's parent record

The following error occurs:

Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_OR_READONLY, Invalid sharing type I: [ShareType]

Both of these look like they might be a Salesforce defect, the following code exhibits the same behaviour for me:

Account a = [SELECT Id FROM Account LIMIT 1];
ContentVersion cv = new ContentVersion(versionData = Blob.valueOf('YQ=='), title = 'test', description = 'test', pathOnClient = '/test.txt');
insert cv;
cv = [select ContentDocumentId from ContentVersion where id=:cv.id];
insert new ContentDocumentLink (ContentDocumentId=cv.contentDocumentId, LinkedEntityId=a.Id, ShareType='V');

ie the error messages are the same depending on ShareType when Content disabled, and succeeding with Content enabled. Inserting a ContentDocumentLink in a separate transaction succeeds with Content disabled.

In Summer 17 prerelease orgs the issue is not reproducible, so might disappear in time.

It'd be helpful if the readme could note this, or even better for the package UI to flag it if you are able to detect if Content is enabled.

douglascayers commented 7 years ago

Thanks for the detailed information @jamesmelville!

Glad to hear it's not happening in Summer '17 orgs so hopefully this issue will magically disappear.

I'll do some testing on my end and hope that I can't reproduce in Summer '17 either =)

douglascayers commented 7 years ago

Hi @jamesmelville,

Have you had any more issues with this? If not, I'm going to go ahead and close this issue. If you do encounter any more problems please open a new GitHub issue for me to investigate.

Thanks,

Doug

unidha commented 7 years ago

Hi,

I download new release of your apps.It's cool but I still face the issue

INSUFFICIENT_ACCESS_OR_READONLY, Invalid sharing type I .

I face this today. I developed vf page to check on how many attachment that I have, and how many that yet to be converted.I run the job, the job is completed but I got the above issue in the log. And some of the attachment is not converted, some yes.Could it be once it hit exception above it will stop converting?

Again, thank you for developing such wonderful app.I have been following you since last year =)

douglascayers commented 7 years ago

Hi @unidha,

Thanks for the kind feedback. Sorry you're hitting an issue. Is your problem related to having CRM Content disabled in your org? Does the issue go away if you enable CRM Content?

Do you notice any correlations among the parent object types of the attachments or the user license types of the attachment owners when this error occurs? For example, does the error happen for attachments belonging to object X? Or does the error happen for attachments owned by community users?

Thanks,

Doug

douglascayers commented 6 years ago

Since 1.2 release of the app I do not explicitly set the Visibility or ShareType on the ContentVersions, they use the Salesforce platform defaults.

Closing issue, but simply reply if still encountering issues.

Thanks