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
Arun KumarArun Kumar 

Error in writing Test Class for ContentVersion() Object

Hi,

I have getting the error while running the below test code:

You cannot set custom fields or tags on a document published into a private library. Fields set: Opportunity,Account: []

ContentVersion testContentInsert = new ContentVersion(); 
testContentInsert.ContentURL='http://www.google.com/'; 
testContentInsert.Title = 'Google.com'; 
testContentInsert.RecordTypeId = ContentRT.Id;
testContentInsert.Account__c = acc.Id;
testContentInsert.Opportunity__c = opp.Id;
insert testContentInsert; 
Amit Chaudhary 8Amit Chaudhary 8
Please check below post. I hope that will help you
1) https://developer.salesforce.com/forums/?id=906F00000008lcnIAA
public ID setupContent(){ 
RecordType ContentRT = [select Id FROM RecordType WHERE Name='Sales Documents'];
 ContentVersion testContentInsert =newContentVersion(); 
 testContentInsert.ContentURL='<a target="_blank" href="http://www.google.com/';" rel="nofollow">http://www.google.com/';</a> 
 testContentInsert.Title ='Google.com'; 
 testContentInsert.RecordTypeId = ContentRT.Id; 
 insert testContentInsert; 

 ContentVersion testContent = [SELECT ContentDocumentId FROM ContentVersion where Id = :testContentInsert.Id]; 
 ContentWorkspace testWorkspace = [SELECT Id FROM ContentWorkspace WHERE Name='Opportunity Documents ']; 
 ContentWorkspaceDoc newWorkspaceDoc =newContentWorkspaceDoc(); 
 newWorkspaceDoc.ContentWorkspaceId = testWorkspace.Id; 
 newWorkspaceDoc.ContentDocumentId = testContent.ContentDocumentId; 
 insert newWorkspaceDoc;
 testContent.iPad_Content_Views__c =0; 
 update testContent;
 return testContentInsert.Id;
Please let us know if this will help you

Thanks
Amit Chaudhary
 
Arun KumarArun Kumar
Hi Amit,

If you can have a look on my code, my code matches the blog's code. the difference is I am using two custom field for Account and Opportunity on Contant Version object.


So when I am trying to insert this record I am getting the error.

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, 

You cannot set custom fields or tags on a document published into a private library. Fields set: Opportunity,Account: []