Fixing “Implementation restriction: FeedItem requires a filter by Id” in LWC Apex

If you’ve worked with FeedItem in Apex (especially from LWC, Sites, or Experience Cloud users), you may hit this error:

Implementation restriction: FeedItem requires a filter by Id

At first glance, this is confusing—because your query already includes filters like ParentId.

But the real issue is deeper than SOQL syntax.


🚨 The Misleading Query

@AuraEnabled(cacheable=true)
public static List<FeedItem> getFeedItems(Id recordId) {
    return [SELECT Id, Body, CreatedDate 
            FROM FeedItem 
            WHERE ParentId = :recordId
            ORDER BY CreatedDate DESC];
}

This looks perfectly valid… yet it fails in many scenarios.


🤔 Root Cause (Important)

The error is NOT just about filtering.

  • Works for Admin users
  • Fails for standard / guest users

The actual reason:

  • FeedItem is heavily restricted internally
  • Requires elevated access like View All Data in many cases
  • Execution context matters more than query structure

⚠️ Why It Works for Admin but Not Others

  • Admin users bypass internal restrictions
  • Other users are blocked from non-selective feed scans
  • Salesforce enforces hidden constraints on Chatter objects

This is why the error message is misleading—it’s actually a security + execution context issue.


✅ Solution: Inner Class with without sharing (Recommended Pattern)

A clean and safe workaround is to isolate the query inside an inner class with without sharing.

This allows controlled bypass of sharing rules without exposing your entire controller.

💡 Example

public with sharing class FeedController {

    @AuraEnabled(cacheable=true)
    public static List<FeedItem> getFeedItems(Id recordId) {
        return FeedQueryService.fetchFeedItems(recordId);
    }

    // Inner class bypassing sharing
    public without sharing class FeedQueryService {

        public static List<FeedItem> fetchFeedItems(Id recordId) {
            return [SELECT Id, Body, CreatedDate
                    FROM FeedItem
                    WHERE ParentId = :recordId
                    ORDER BY CreatedDate DESC
                    LIMIT 50];
        }
    }
}

✔️ Why This Works

  • Main class still respects sharing rules
  • Only the query runs in elevated context
  • Minimizes security exposure
  • Works well for LWC + Experience Cloud scenarios

⚠️ Important Notes

  • This bypasses record-level sharing, not object permissions
  • Use carefully—don’t expose sensitive data
  • Always filter by ParentId and use LIMIT

✅ Alternative Options

1. Grant Elevated Permissions

  • View All Data
  • Modify All Data

⚠️ Not recommended for normal users

2. Use Connect API (Best Practice for Chatter)

  • Use ConnectApi instead of SOQL
  • Handles permissions internally

❌ What NOT to Do

  • Don’t rely on FeedElement workaround
  • Don’t assume ParentId filter is enough
  • Don’t ignore execution context

💡 Key Takeaway

This error is misleading.

The real issue is:

  • 🔐 Execution context
  • 👤 User permissions
  • ⚡ Internal platform restrictions

The inner without sharing pattern is often the most practical fix in real-world LWC implementations.


🎯 Conclusion

If your query works for Admin but fails for others, stop tweaking SOQL.

Focus on who is running the query and how.


Need help with Salesforce architecture or LWC performance issues?
Explore more deep-dive articles on sfdcian.com.