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
Damien_Damien_ 

How do i public Content to Library?

I need to insert Content into my test class so that I can test a method.  The problem is that I have custom fields and get 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 personal library. Fields set: Type of Document,Quarter: []

 

So I need to figure out how to publish into a personal library to set these fields.  Does anyone know how to do this through code?

 

 

ContentVersion version = new ContentVersion();
version.Title = 'test';
version.ContentUrl = 'www.google.com/';
version.Quarter__c = 'Test Quarter';
version.Type_of_Document__c = 'Test type';
insert version;

I also tried creating an account in the test class and setting the

version.FirstPublishLocationId = acc.Id;

and got the error:

 

System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, Content cannot be inserted as a child of record 001V0000007AcyK.: [FirstPublishLocationId]