You need to sign in to do that
Don't have an account?

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?
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?
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;
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.
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