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
jaxdmasterjaxdmaster 

CRM Content document using Apex

Hi Guys,

 

I've custom VF page which uploads a doc into CRM Content. I successfully did this but when I do this it goes to personal document but I want it to go to a shared lib. How can I do this? Please find my code below:

ContentVersion content = new ContentVersion();
content.versionData = file;
content.title = title;
content.pathOnClient = fileName;
insert content;

 

Best Answer chosen by Admin (Salesforce Developers) 
IspitaIspita

Hi,

That is what the documentation says you can only specify this value , when you are creating it for the first time , in all subsequent occasions it become read-only field. Ok so want to set it while creation let me check and circle back to you.

All Answers

IspitaIspita

Hi  jaxdmaster,

Have you tried / studied the field "FirstPublishLocationId"?

This is what this fields is all about :-

FirstPublishLocationId gives ID of the location where the version was first published. If the version is first published into a user's personal library or My Files, the field will contain the ID of the user who owns the personal library or My Files. If the first version is published into a public library, the field will contain the ID of that library.

This field is only set the first time a version is published via the API. It isn't set when a version is published in Salesforce CRM Content or uploaded in Chatter. After the version is published, it is a read-only field.

If you don't set a FirstPublishLocationId via the API, this field defaults to the user's personal library, unless Origin is set to H, then this field defaults to My Files.

Hope this helps.

 

jaxdmasterjaxdmaster

Thanks for reply!

 

I tried what you suggested. i.e.

		Attachment__c att = attachFile();
		ContentVersion cv = createContentDocument();
		cv.FirstPublishLocationId = '058U00000000GDkIAM';

 The hardcoded ID is id of my public lib. What it doent work. it says field is not writable. I want when I create a doc using apex it should go to public lib. Pls help me in this.

 

Thanks

IspitaIspita

Hi,

That is what the documentation says you can only specify this value , when you are creating it for the first time , in all subsequent occasions it become read-only field. Ok so want to set it while creation let me check and circle back to you.

This was selected as the best answer
Bhushan_27Bhushan_27

Hi Ispita,

 

I need to access suggested tags and dispaly it on my vf page, so that user will enter only those tags not random tags while uploading a content.

 

I use that VF page to upload content to  a Library.

 

Thanks,