In Apex, I'm trying to insert a FeedItem then a FeedAttachment so the Chatter post has a file related with it. However, when trying to follow the example in the documentation I'm getting this error:

System.DmlException: Insert failed. First exception on row 0; first error: INVALID_OPERATION, Cannot create, update or delete Feed Attachment

Sample Code from Documentation

enter image description here


Upon re-reading the FeedAttachment documentation there is this notice under Special Access Rules:

You can read, create, update, or delete a FeedAttachment only if you have the corresponding access to the associated FeedItem.

Apparently, when inserting a FeedAttachment this is considered an update to the FeedItem. Therefore, you need Allow users to edit posts and comments enabled under Setup | Customize | Chatter | Chatter Settings.

enter image description here

Fun Fact: You can insert multiple FeedAttachment's to a single FeedItem Chatter post. So you can associate File(s) and up to one URL link with the post.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.