• Rucha Pradhan-Thakkar
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
below is my code in test class in which I am getting the exception.
Can anyone help me with root cause and solution?

ContentVersion cv = new ContentVersion();
        cv.Title = 'Test Content';
        cv.PathOnClient = 'test';
        cv.VersionData = EncodingUtil.base64Decode('Unit Test Attachment Body');
        cv.NetworkId = // customer community network id;
        insert cv;
Id contentDocumentId = [select Id, ContentDocumentId, OwnerId from ContentVersion where Id = :cv.Id].ContentDocumentId; 
      List<ContentDocument> documents = [SELECT Id, Title, LatestPublishedVersionId FROM ContentDocument where ID =:contentDocumentId];
      System.assertEquals(documents.size(), 1);
      System.debug('DocId : '+contentDocumentId);
      ContentDocumentLink cdl = New ContentDocumentLink(); 
      cdl.LinkedEntityId = caserec.id; // id of a case record inserted earlier in the method
      cdl.ContentDocumentId = contentDocumentId;
      cdl.shareType = 'V';
      insert cdl;   // getting exception on this line.