Skip to main content

"Implementation restriction: FeedItem requires a filter by Id" when running query against FeedItem

Recently i faced an issue where a SOQL query against Feed Item object was failing with the error "Implementation restriction: FeedItem requires a filter by Id"

SELECT ID, CreatedDate, CreatedById, CreatedBy.FirstName, CreatedBy.LastName, ParentId, Parent.Name, Body, 
(SELECT ID, FieldName, OldValue, NewValue FROM FeedTrackedChanges ORDER BY ID DESC) 
FROM FeedItem WHERE CreatedDate > LAST_MONTH  ORDER BY CreatedDate DESC

The main reason as the documented here is when we want to directly query the Feed Item object, Either one of the below things should be true

1. The context user should have 'View All Data' permission in the assigned profile/permission set.
2. The class should be annotated with 'Without Sharing'

Without "View All" permission every feed item examined by the query needs to be access checked and potentially discarded, which is a very expensive operation. Given that there are potentially millions of feed items in an organization, most of which a user might not have access to, finding a page of accessible feed items would require reading through too many items. Error message that is thrown is basically stating you can't run this query until you provide the exact FeedItem record Id. Reason for requiring "View All" is basically with execution times and resource consumption. 

Also if "Without Sharing" is used at class level,  The query is going to by pass access checks.

Hope this article helps and Let me know if you find any other ways to solve this issue.

Thank you for your time in reading this.
Cheers :)

Comments