• mattatrenet
  • NEWBIE
  • 0 Points
  • Member since 2005

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

I have custom fields on the ContentVersion object and I need to test querying ContentVersion based on these custom fields in my Apex test method.

 

I've tried creating a new ContentVersion in my test method:

--------------------------------------------------------------------------------

ContentVersion contentVersionObj = newContentVersion();

contentVersionObj.ContentURL = 'http://www.google.com';

contentVersionObj.title = 'Google';

contentVersionObj.Enablement_Area__c = 'Acct Mgmt';

insert contentVersionObj;

--------------------------------------------------------------------------------

 

However, when I try to test that, I got an error:

--------------------------------------------------------------------------------

15:55:36.756 (756244000)|EXCEPTION_THROWN|[136]|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: Enablement Area: []

15:55:36.757 (757794000)|FATAL_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: Enablement Area: []

--------------------------------------------------------------------------------

 

Ok, so based on the ContentVersion docs (http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_contentversion.htm) I need to assign a value to FirstPublishedLocationId in order to have the ContentVersion not be assigned to a personal library.

--------------------------------------------------------------------------------

ContentWorkspace library = [SELECT id FROMContentWorkspace LIMIT 1];

ContentVersion contentVersionObj = newContentVersion();

contentVersionObj.ContentURL = 'http://www.google.com';

contentVersionObj.title = 'Google';

contentVersionObj.Enablement_Area__c = 'Acct Mgmt';

contentVersion.FirstPublishLocationId = library;

insert contentVersionObj;

--------------------------------------------------------------------------------

 

Only, when I run that, I get another error:

--------------------------------------------------------------------------------

Expression cannot be assigned

--------------------------------------------------------------------------------

 

So, I guess I can't assign to the FirstPublishLocationId field...

 

Is there any way to create a ContentVersion object with a custom field in an Apex test method?

 

I'm doing this all in a sandbox and using the Force.com IDE if it matters.

 

Thanks,

Matt

I have custom fields on the ContentVersion object and I need to test querying ContentVersion based on these custom fields in my Apex test method.

 

I've tried creating a new ContentVersion in my test method:

--------------------------------------------------------------------------------

ContentVersion contentVersionObj = newContentVersion();

contentVersionObj.ContentURL = 'http://www.google.com';

contentVersionObj.title = 'Google';

contentVersionObj.Enablement_Area__c = 'Acct Mgmt';

insert contentVersionObj;

--------------------------------------------------------------------------------

 

However, when I try to test that, I got an error:

--------------------------------------------------------------------------------

15:55:36.756 (756244000)|EXCEPTION_THROWN|[136]|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: Enablement Area: []

15:55:36.757 (757794000)|FATAL_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: Enablement Area: []

--------------------------------------------------------------------------------

 

Ok, so based on the ContentVersion docs (http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_contentversion.htm) I need to assign a value to FirstPublishedLocationId in order to have the ContentVersion not be assigned to a personal library.

--------------------------------------------------------------------------------

ContentWorkspace library = [SELECT id FROMContentWorkspace LIMIT 1];

ContentVersion contentVersionObj = newContentVersion();

contentVersionObj.ContentURL = 'http://www.google.com';

contentVersionObj.title = 'Google';

contentVersionObj.Enablement_Area__c = 'Acct Mgmt';

contentVersion.FirstPublishLocationId = library;

insert contentVersionObj;

--------------------------------------------------------------------------------

 

Only, when I run that, I get another error:

--------------------------------------------------------------------------------

Expression cannot be assigned

--------------------------------------------------------------------------------

 

So, I guess I can't assign to the FirstPublishLocationId field...

 

Is there any way to create a ContentVersion object with a custom field in an Apex test method?

 

I'm doing this all in a sandbox and using the Force.com IDE if it matters.

 

Thanks,

Matt