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
prageethprageeth 

New To Salesforce CRM Content

Hi all;

I have several questions about Salesforce CRM Content.

1. Can I upload a file to Salesforce CRM Content by using Apex code? If so please tell how can I do that.

2. Can I display an image uploaded to Salesforce CRM Content on a visualforce page?

3. Is there a sObject which represents the Salesforce CRM Content, so that I can query data from that sObject?

 

If anybody knows an answer for at least one question please help me. If any question is not clear I'm ready to explain further. Thanks.

SargeSarge

Hi Prageeth,

 

    I think you can upload a file to content from Apex. Check out the this link for the SObject docs for storing the content.

The field "VersionData" will be helpful to store the binary of the file you want to store. From docs VersionData is base64 type and you might have to use <apex:inputFile> tag to select the file. The content will be tagged as type blob in apex controller class. Then you need to convert the blob to base64 using EncodingUtil class (System class).

 

Also you need keep in mind to fill the required information as given in docs as upload is done through apex and not by the  system. Also please note that this will work on apex classes after API version 17.0.

For querying the content, VF page is not much suitable to show the data as view state size is limited for VF page. Instead you can use client side programs that will show the content. E.g. Java client s/w, Adobe flex (not very sure).

 

Hope this helps.

 

Cheers..

 

gtuerkgtuerk

Here's a link to a step-by-step approach to programmatically uploading Content.  Should give you what you need.  Now, if you find an answer to embedding Content in VF, please let me know - I have an open post on this that SF seems to be ignoring... 

 

Programmatically Upload Content

prageethprageeth

Hello 

Attachment attachment = new Attachment();
attachment.ParentId ='006A00000079noP';
attachment.name = 'Test.pdf';
attachment.body = page.testVfPage.getContentAsPDF();
insert attachment;

 

Similarly can I upload an existing PDF file to the CRM Content ?

Any help would be highly appreciated.

I am ready to explain my requirement further if needed. Thanks.

 

prageethprageeth

Hello;

Finally I found something which looks like a solution. I could upload a VF page by using this method.

 

public ContentVersion myPage = new ContentVersion();
myPage.FirstPublishLocationId = '058A00000004J2K';//WorkspaceId
myPage.PathOnClient = 'Test.pdf';//Name of the file after uploaded
myPage.VersionData = page.testVfPage.getContentAsPDF();
insert myPage;

 

I am not very much sure whether this code is correct. If anybody can find errors in this code please point me to the correct direction. 

Thank you.

James Simpson 6James Simpson 6
Hi Prageeth,
I have a similar need.  We have a VF Component which produces a PDF for us that is used by a VF page that creates a PDF preview in the browser. But I want to write a VF page that pushes the PDF either into Notes & Attachments or into a ContentWorkspace.  Can you please help point me to a post or article that explains how to create the VF page to do that?
Thanks,
James