Discussions
- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- Security
- Mobile
- Force.com Sites & Site.com
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby
- Desktop Integration
- APIs and Integrations
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- AppExchange Directory & Packaging
- Salesforce Labs & Open Source Projects
- Other Salesforce Applications
- Jobs Board
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- Chatter Development
- :
- Attach a file to a Chatter Comment via Soap API
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Attach a file to a Chatter Comment via Soap API
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
09-14-2012 02:42 PM
I am trying to transfer Chatter posts from one instance to another. I am running into problems moving attached files within comments (FeedComment items).
I realize that the files attach to comments via the RelatedRecordId (mapped to the ContentVersion object) and I am trying to transfer the file by:
1. Get the VersionData from the ContentVersion that is attached to the comment
2. Create the file on the destination environment by writing the file to disk locally and setting the VersionData, PathOnClient (linked to the file that was just created locally), Description, Title
3. Get the ID of the newly created ContentVersion object (returned by the SaveResult array)
4. Set the FeedComment's RelatedRecordID to the new ID created in step 3
5. Upload the comment
The result is the comment is created but the file is not found, resulting in "The file is no longer available.". Am I missing a step in the file linking?
Note: My file creation process is similar to this - if there is a way to upload a ContentVersion file without creating it locally, I'd happily check that out.
Solved! Go to Solution.
Re: Attach a file to a Chatter Comment via Soap API
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
09-16-2012 04:23 PM
I'm not entirely sure how to do it in Soap, but you can post a file to a comment using the Chatter REST API: http://www.salesforce.com/us/developer/docs/chatte
Make a POST to /chatter/feed-items/feedItemId/comments with Content-Type multipart/form-data, with a binary part named "feedItemFileUpload", a text part called "title" with the file title, and a text part called "text" with your feed item text. Alternately, you can make a regular non-multipart request with the query parameter "contentDocumentId" set to the pre-uploaded content id.
Re: Attach a file to a Chatter Comment via Soap API
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
09-17-2012 10:33 AM - edited 09-17-2012 10:35 AM
Update:
I have broken the process down and I have found a different problem. I am able to upload files as ContentVersions through the API (though, I cannot see the file through the All Files interface within Chatter, I can see them when I query ContentVersion) and I am able to attach files that I have uploaded through the interface to new comments using the API. I cannot, however, attach files that I have uploaded via the API.
I get the following error message when I try to attach an API-uploaded ContentVersion to an API-created FeedComment item:
The Insert failed because: You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary.
The message doesn't really make sense since I am using the User ID for the file and comment of the admin account I am logged in as to do the API work.
Is there another step in creating a ContentVersion file that will make it attachable?
Re: Attach a file to a Chatter Comment via Soap API
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
09-17-2012 10:44 AM
When you insert the ContentVersion objects via the API, what are you specifying for the Origin field? (It can be Chatter (H) or Content (C), which is the default if not specified). I ask because if the files are assigned to Content, then some security rules are enforced with regards to sharing/posting into Chatter Feeds. If you're assigning to Content, or leaving it defaulted, try specifying it and see if that works.
Thanks,
Rob
Re: Attach a file to a Chatter Comment via Soap API
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
09-17-2012 10:50 AM
That fixed it. Thanks for your quick reply!
Re: Attach a file to a Chatter Comment via Soap API
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
09-17-2012 10:59 AM
Great glad to hear it's working.
Just to clarify when I said 'security rules' for files that belong to Content. If you publish a ContentDocument / ContentVersion into a library (ContentWorkspace), it is possible to share that file into Chatter afterwards, in the UI and using the SObject and Connect APIs. Typically you'd do that by inserting a FeedItem (FeedItemType = ContentPost), or a FeedComment that references the file using its ContentVersionId. You can also share the file with groups, users and with the whole company by inserting a ContentDocumentLink to attach the file to a specific location.
To do any of those things though, the user performing the operation needs to be a member of the Library with a Library Permission called "Attach or Share Content". It's mentioned in the docs here: https://login.salesforce.com/help/doc/en/content_w
This is only relevant if you're using the Salesforce Content application & Libraries. For files added to Chatter directly, this doesn't apply.
Re: Attach a file to a Chatter Comment via Soap API
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
03-19-2013 05:13 PM - edited 03-19-2013 07:26 PM
I can't stress enough how this post is handy. I managed to migrate the chatter data successfully.
Did you manage to migrate the likes against a chatter post or at least the like count?

