+ Start a Discussion
Mahmood ButtMahmood Butt 

Error uploading Enhanced Notes - Invalid ShareType

I have migrated Notes to Enhanced Notes (ContentNote) using SF data loader. Most of the records are migrated successfully, only in few of the records I am receiving following error:

Invalid sharing type "I"
I tried changing the ShareType to 'C' (Collaborator) but same error. Does it have something to do with security settings of the Parent (LinkedEntityId) record?

P.S. All the error records have ParentIds in Quote ('0Q0') or Email Template ('00X') objects.
ShareType is that even a field on ContentNote?
Mahmood ButtMahmood Butt
ShareType is field on "ContentDocumentLink" object that is used to link the ContentNote record with another record in the system. So, to tell about the note and to what type of record it is related to.
Can you check if the quote object is visible to you? and also the email template folder is visible to you?
Brian Tang 12Brian Tang 12
Hey Mahmood, I'm running into the same issue with regards to ShareType. Did you ever figure it out? I'm trying to do the same, creating a Docket__c record and attaching a File to it in one click.

I create the Docket record and a ContentVersion record which generates a ContentDocument record. I grab that ContentDocument record and tie it to the Docket record through the ContentDocumentLink record that I create. It only works if I set ShareType to 'V', but I want the ShareType of the file to be inferred based on access to the parent of the file, the Docket record.

"Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_OR_READONLY, Invalid sharing type I: [ShareType]"
// Create File and set the parent to the previously-created Docket
			insert file;
		} catch (Exception e){
			system.debug('File Attachment Debug Statement: ' + e);

		// Query for the newly created ContentDocumentId
		if(file.id != null){
			List<ContentDocument> newContentDocList = new List<ContentDocument>([SELECT id FROM ContentDocument WHERE LatestPublishedVersionId=: file.id LIMIT 1]);

			ContentDocument newContentDoc = new ContentDocument();
			newContentDoc = newContentDocList[0];

			// Create the ContentDocumentLink record that connects the ContentDocumentId to the Docket__c record
			ContentDocumentLink docLink = new ContentDocumentLink();
			docLink.LinkedEntityId = newDocket.id;
			docLink.ContentDocumentId = newContentDoc.id;
			docLink.ShareType = 'I';
			docLink.Visibility = 'AllUsers';
			insert docLink;

Ankita Gupta 96Ankita Gupta 96
Did you find any resolution for this ? Facing the same issue - the code works when run on Dev console but not via Page:

        ContentNote cNote = new ContentNote();
        cNote.title='Untitled Note';insert cNote;
        System.Debug('Content Note : ' + cNote);
        ContentDocumentLink cdLink = new ContentDocumentLink();
        cdLink.ContentDocumentId = cNote.id;
        System.Debug('Content Document Link : ' + cNote.id);
        cdLink.LinkedEntityId = agreement.id; //CustomObject record retreived via Controller on page (If i hardcode this on Developer console it works but not when invoked via Apex Page method.)
        cdLink.Visibility = 'AllUsers';
        cdLink.ShareType = 'I';
        insert cdLink;
        System.Debug('Content Document Link : ' + cdLink);
        system.debug('Successfully Created Empty Note : ' + cNote.id);
Joseph Ramírez MorenoJoseph Ramírez Moreno
Is there a solution for this? I'm running into the same problem when I try to share a file with an user via APEX. I need to insert a ContentDocumentLink in order to do that and it is not letting me fill that value.
Joseph PescatelloJoseph Pescatello
I'm seeing a very similar error when inserting ContentDocumentLinks"

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

It appears when a unit test is run, but only SOMETIMES. Maddening.
Clive HillClive Hill
Same problem here...