You need to sign in to do that
Don't have an account?
liron169
Delete FeedItem + Attachment
Hi,
If I create FeedItem + Attachment and after a period I need to delete all the old FeedItem -for example, those that before 30 days.
<Note that all this is with apex code, not manually>
I understand that deleting the FeedItem is not deleting the attachment file, so I found that I can delete the attachments by querying ContentDocument object.
The problem is that I want to delete only the attachment that related to the feeds that were deleted, not all those in ContentDocument.
Assume that I can mark those attachments in some way (when creation) that will help to retrieve only them when need to delete them.
But perhaps I can avoid it? Does SF store in some way the connection between the FeedItem in its attachment?
If I create FeedItem + Attachment and after a period I need to delete all the old FeedItem -for example, those that before 30 days.
<Note that all this is with apex code, not manually>
I understand that deleting the FeedItem is not deleting the attachment file, so I found that I can delete the attachments by querying ContentDocument object.
The problem is that I want to delete only the attachment that related to the feeds that were deleted, not all those in ContentDocument.
Assume that I can mark those attachments in some way (when creation) that will help to retrieve only them when need to delete them.
But perhaps I can avoid it? Does SF store in some way the connection between the FeedItem in its attachment?
Don't think there is a way to identify the same AFAIK.
I didn't clearly understand -
Does only the information of the file is being stored in the feedItem? Does it contain the URL to the place where the file actually stored?
I am having a similar issue.
I am able to delete the FeedItem(post) but am not able to delete the associated FeedAttachment.
Is there a resolution for this?
Thanks!
I think you can do something like this using ContentDocumentLink
The above code will not work as expected if the same content document is used in multiple feed items. I think you can use aggregrate query in those case scenarios.
To test the above code, I added an attachment to the opportunity feed and I'm able to get the documnet id associated to that feed
Regards,
Naga
FeedAttachments will automatically deleted when you delete FeedItem. Can you check that once.
Thanks,
Naga
Hey Naga!
What I was doing:
I created a custom quick action button on the feed for the case object in which I was adding a contentversion and a contentdocumentlink to link it with the case. Then, I was adding a feeditem and feedattachment which I was associating with the contentversion I added early on.
When I used to manually delete the feeditem, the file was not getting deleted which was my problem.
What I was doing wrong:
As you said, deletion of feeditem will automatically delete the feedattachment.
When I delete the feeditem manually, the feedattachment was getting deleted but the conetntdocumentlink linking the contentversion to the feed was not so the file still showed in the related list. I simply stopped adding a contentdocumentlink and that solved my issue. So now the contentversion is linked from the feedattchment to the case and not through the contentdocumentlink.
However, there is still the issue with orphaned contentversion records taking space after the feeditem and feedattcahment is deleted but I am fine with that.
Thanks!