1

Trying to create a Content Document Link linking a text file to a custom object (an error log object). But keep getting the following error:

First error: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, You cannot create a link for a document in a private library: ContentDocument ID: [ContentDocumentId]

Any help would be appreciated!

    String now = Datetime.now().format();
    String payload = 'Sync Action: ' + syncActionName + '\nTimestamp: ' + now + '\n\n' + currentPayload;

    // create the payload txt file
    ContentVersion conVer = new ContentVersion();
    conVer.Title = 'Payload ' + now;
    conVer.VersionData = Blob.valueOf(payload);
    conVer.PathOnClient = 'payload' + now + '.txt';
    conVer.ContentLocation = 'S';
    insert conVer;
    Id conDocId = [SELECT Id, ContentDocumentId FROM ContentVersion WHERE Id =:conVer.Id].ContentDocumentId;

    // link the payload txt file to the error sync log
    ContentDocumentLink conDocLink = new ContentDocumentLink();
    conDocLink.ContentDocumentId = conDocId;
    conDocLink.LinkedEntityId = errorLogId;
    conDocLink.ShareType = 'I'; 
    insert conDocLink;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.