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

Chatter Feed Item and Attachment + insufficient privileges error

I am having trouble inserting a list of chatter feed items of type 'ContentPost'. These feed items are being dynamically created for a list of contacts/campaign members (post.ParentId = 'contact id goes here') associated to a campaign; as well as the campaign itself. While I am iterating over the list of contacts I am also creating an attachment for each of them then
associating this attachment to the feed item. Both Attachments and Feed Items are added to separate lists then post for loop are inserted into the database.


I am able to successfully insert the chatter feed items (as text post posts, not content) if I don't associated the attachments, however when I associate the attachment body to the content data field of the feed item I get the following error:


Insert failed. First exception on row 0; first error: INVALID_ID_FIELD, 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.: []


I am running this as a system administrator on our dev sandbox, so I'm not sure what is causing this insufficient privileges error. I would appreciate any help on this, and if needed I can provide a more technical description with code snippets of the logic.


In the system admin profile do check the following:-


  • Insert System Field Values for Chatter Feeds if it is switched on or not

It is checked. I have been able to insert chatter feeds (FeedItem) objects from a list, the issue occurs when I try to add an attachment to it. The following code snippet explains the issue a bit more. The pdfBody variable comes from the URL of a visual force page rendered as PDF. Prior to inserting the FeedItem I create an Attachment with the same visualforce page and that is generated and attached to the campaign without an issue.



PageReference pdfPage = new PageReference(url);

// Create the attachments
Attachment pdf = new Attachment();
Blob body;
body = pdfPage.getContent();
pdf.Body = body;
pdf.Name = letter + ' Letter.pdf';
pdf.IsPrivate = false;
pdf.ParentId = parentId;

Blob body = pdf.Body;
String name = pdf.Name;

FeedItem post = new FeedItem();
post.ParentId = parentId;
post.Body = letter + ' Letter Sent';
post.CreatedById = chatty.Id;

// The issue occurs with the following lines of code. When commented out I am able to successfully insert chatter // feeds. The insufficient privileges error occurs when these lines are uncommented.
post.Type = 'ContentPost';
post.ContentData = body;
post.ContentFileName = name;



We are having the exact same error in a slightly different context: while trying to attach a ContentPost that belongs to a case to another case (that is a clone of the first case).




Can any one of you please advise , i am trying to move chatter files from one org to other, what is the best way of doing this?




I have the same problem, we access Chatte file from Java


sarvendra aeturu 10sarvendra aeturu 10
Hi all Chatter feed item id is not searchable. the only way to achive this is to fetch the id and convert that id to a attachment Id. this resolves your issues. 

i do have the same issue. i am working on the same. once i am done with this i can able to give you the updates.

use work bench to verify your Attachment Id.