You need to sign in to do that
Don't have an account?
Insert a copy of Attachment into a Chatter Feed as a File for Sharing
Hi All,
There are plenty of code online that looks at inserting Attachments into Salesforce objects however I have a requirement to do something a little different to this.
Whenever a file is manually uploaded onto a Case object as an Attachment on the Case record, I would like to have a trigger that inserts the same Attachment into the Chatter Feed as a File on the same Case record. Although I can write the trigger of picking up the Attachments fine, I do not know where to start in APEX if I wanted to insert this Chatter Feed File using the trigger.
Could someone please direct me on what standared objects and calls I should be making to insert this Feed File?
Many thanks!
You'd create a FeedItem and set the content fields to the attachment body etc. Here's a snippet of code from one of my dev orgs - its not a trigger, but from a visualforce controller, but should be easy enough to adapt.
Thanks Bob. I got the trigger to add Attachments to the case record Feed and thought I post it for others to work off as well.
Another question though, the reason why I am doing this copy Attachment in the casefeed is because I am trying to take advantage of the 'share via link' (the public link to the file in Content) however according to your response in this post you mentioned that its not possible to get this public link via APEX calls. Obviously I would like to use this link to send our email alerts which include this public link so that the case Teams can access the attachment publically.
Is there another way of doing this or does the Spring 13' release have any new improvements to allow us to do this?
Many thanks for your advise!
There's nothing that I've spotted in the winter 13 release notes that indicates this is supported I'm afraid.
Bob - We have similar code working for attaching documents to a feed and they appear in the feed as expected. Do you know which object you can find details about the Chatter Feed file attahcment like the file name so we can verify attachment in tests?
I think that is a defaul for adding feed files. You may just need to create and after insert trigger that deletes the original Attachement (the 1st one) leaving you with the Feed File attachment in notes and attachments section.
That is a good idea but I think that having a feed version in the notes and attachments related list is not bad after all. If a user deletes the feed attachment type the system will keep the attachment type file, which make sense. So I will keep it like this for now. Thanks for you reply.
What if I want to add files directly to chatter without saving it in "Notes and Attachment". The reason being the PDF that I am generating in VFpage is more than the size limit of Attachment but less than that of FIles. Please let me know, if you guys can give me an idea around this??