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
Samrat ChakrabortySamrat Chakraborty 

trigger to post a pdf generated by vf page onto chatter

I want to post a file as chatter feed when the user clicks "generate PDF" from a visual force page. 
I dont want the file to be saved as "Notes and Attachments". Whatever is the pdf generated on the button click the user should be able to share the same in Chatter.
logontokartiklogontokartik
You can use the FeedItem object and insert the feed,

Here is the similar question that might help you

https://developer.salesforce.com/forums/ForumsMain?id=906F000000092VuIAI
Samrat ChakrabortySamrat Chakraborty
Hi Kartik,
Thanks for the reply, as per the example first the generated pdf is to be saved as Attachment and then inserted in feed. I dont want it to be added in Notes and Attachment, but I want it to be added directly to the files tab in the chatter
logontokartiklogontokartik
It would still be the similar thing, just create an instance of attachment or document that you can use with <apex:inputFile> and use it to create chatter feed item, you dont need to insert attachment if you dont want it. 

Otherwise you can use the Blob type to refer in your VF Page and use that as post.ContentData, hope this helps. 

If you still cannot figure it out, please post your VF page and I will try to create a controller for it. Thank you

Samrat ChakrabortySamrat Chakraborty
<apex:page controller="IPM_ExportPDFController" renderAs="PDF"  >
<apex:stylesheet value="{!URLFOR($Resource.styles,'pdf.css')}"/>

<center><h2><apex:outputText value="{!Bsc.Name__c}"/></h2>
<h2>Meta Information</h2></center>

<table>

<tr><th>Category</th>
    <td><apex:outputText value="{!usr.Category__c}"/></td>
    <th>Project Leader</th>
    <td><apex:outputText value="{!usr.Name}"/></td>
    </tr>
    
<tr><th>Project Idea</th>
    <td><apex:outputText value=""/></td>
    <td><apex:outputText value="{!Bsc.Idea__c}"/></td>
    </tr>
</table>

<h2></h2>
<h2>Background</h2>
<apex:outputText value="{!Bsc.Background__c}"/>
<h2>Opportunity</h2>
<apex:outputText value="{!Bsc.Opportunity__c}"/>
<h2>Scope</h2>
<apex:outputText value="{!Bsc.Scope__c}"/>

</apex:page>
hi Kartik 
First of all thanks for ur reply. I was working on the same approach. Will continue to do that and update if there is any breakthrough. :)
Meanwhile I have attached My VF page to be rendered as pdf as requested.

Thanks a lot
logontokartiklogontokartik
Hmm, very interesting, so are calling this PDF Page from a Visualforce page right? 

When you click on "Generate PDF" button on a Visualforce page, are you calling an action function in your other Controller to redirect to the PDF page?

In that action Button function, you might need to do this

public Pagereference generatePDF(){

//Adding a Content post
FeedItem post = new FeedItem();
post.ParentId = caseId; //eg. Opportunity id, custom object id..
post.Body = 'Attachment added';
Pagereference pdfPage = Page.IPM_ExportPDF;
post.ContentData = pdfPage.getContent(); // You can use this or getContentAsPDF(), but since you are already rendering in PDF,  I dont think you need to do this
post.ContentFileName = 'IPM Export PDF';
insert post;

return pdfPage;

}