We have a class that generates an RSS feed to expose questions from a community on a public website. The Visualforce page for the feed uses a custom controller with the following query, which should return all questions that were not posted to private groups:

List <FeedItem> questionList = [SELECT Id, Title, CreatedBy.Name, Body, NetworkScope, ParentId FROM FeedItem 
            WHERE Type = 'QuestionPost'
            AND ParentId NOT IN (SELECT Id FROM CollaborationGroup WHERE CollaborationType = 'Private')
            AND NetworkScope != null
            AND Visibility = 'AllUsers'
            ORDER BY CreatedDate DESC 
            LIMIT 50];

Guest users on the site are able to see questions asked to private groups even though those feed items should be excluded from the query results. It looks like the inner query (SELECT Id FROM CollaborationGroup WHERE CollaborationType = 'Private') returns null when running as a guest user, which eliminates the filter on private groups.

How can I filter questions made to private groups out of the results?

  • 1
    What is your class declaration? Are you using without sharing? – pchittum Apr 9 '15 at 23:06
  • Yes, class is without sharing. – meerkatz Apr 9 '15 at 23:22
  • 1
    Try using with sharing. – slashApex Apr 9 '15 at 23:36
  • Using 'with sharing' does surface a query exception, but still doesn't get me where I'm trying to go. – meerkatz Apr 10 '15 at 16:06

Your Answer

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

Browse other questions tagged or ask your own question.