function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Hugh Wheeler 54Hugh Wheeler 54 

INVALID_FIELD_FOR_INSERT_UPDATE, Visibility InternalUsers is not permitted for this linked record

We are creating a note against a custom object.  We are inserting a ContentDocumentLink record usinmg the following code:

              ContentDocumentLink cdl = new ContentDocumentLink();

              // link the link object to the note
              cdl.ContentDocumentId = cn.Id;

              // link to sObjects by Id
              cdl.LinkedEntityId = caseId;

              // set visibility
              cdl.Visibility = 'InternalUsers';

              // set ShareType
              cdl.ShareType = 'I';

I have tried using both a system admin and the normal user. This code works fin in our development environment but fails in our test environment.

I can only think that there is a setting in our test environment for which the sharing type and visibility combination is invalid, but I have no idea what that could be.  I have turned the content feature setting on for both users and that made no difference.  I have also cheked the OWD (Private) and it is the same in both environments.  

Has anyone seen this issue before?
 
Deepak Pandey 13Deepak Pandey 13
Hi High ,

You can only assign contentDocument, you can't insert.

ContentVersion cv = new ContentVersion();
            cv.versionData = file;
            cv.title = fileName;
            cv.pathOnClient ='/'+fileName;
            insert cv;
            
            list<ContentVersion> cvRes = [select id, ContentDocument.id, ContentDocument.title 
                             from ContentVersion where id= :cv.id limit 1];
                             
             ContentDocument cd = cvRes[0].ContentDocument;
Hugh Wheeler 54Hugh Wheeler 54
Deepak,

Thanks for getting back to me.  I am creating ContentNote records first and then using the ContactDocumentLink to assign it to a custom object.

         ContentNote cn = new ContentNote();

          // give the note a subject
          cn.Title = source + ' - ' + st.Name;
          cn.Content = Blob.valueOf(st.Description__c);
          newNote.add(cn);
          insert newNote;

Then I loop through the inserted notes and hook them to the correct objects

ContentDocumentLink cdl = new ContentDocumentLink();

              // link the link object to the note
              cdl.ContentDocumentId = cn.Id;

              // link to sObjects by Id
              cdl.LinkedEntityId = caseId;

              // set visibility
              cdl.Visibility = 'InternalUsers';

              // set ShareType
              cdl.ShareType = 'I';

              insLinks.add( cdl);

             insert insLinks;

So I am creating all the correct objects, its just that the Visibility setting seems to be incompatible with something else in the environment.
Deepak Pandey 13Deepak Pandey 13
Hello High,

I recently inserted, please check what are you miss.
code like
ContentDocumentLink cdl = New ContentDocumentLink(LinkedEntityId = LstCon[0].AccountId, ContentDocumentId = cd.Id, ShareType = 'V');
                insert cdl;

       check this link, it might be help you.
https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_contentdocumentlink.htm
https://developer.salesforce.com/forums/?id=906F0000000kA6aIAE