I have the following apex code that runs to get the EntitySubscriptions for a set of ids so they can be deleted to clean up the chatter feed.
public static List<EntitySubscription> getAllFollowers(Set<Id> ids) {
return [
select parentId,
subscriberId
from EntitySubscription
where parentId in :ids
limit 1000
];
}
This code has been in production and running without a hitch for over a year and this past weekend, we started getting the following error everytime it runs.
System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times)
To make this issue even more "interesting" the error only presents itself when it is triggered by a non-system administrator. From what I was reading IN should be considered a selective query.
We currently have 89336 EntitySubscription active records and 11301 records that show up in we only look at isDeleted. This total does push us over 100000 records. Any ideas on how to make this work again?
NOTE: I did try (as a temporary solution) using Database.emptyRecyclingBin to remove the 11301 records and it would not remove them. Also trying to 'purge' them in workbench results in 'Invalid Record Id; No Recycle Bin Entry Found'
EntitySubscription
objects and the job did come along and clean them up. So that bought us some time in prod. Also that same job made it so we could reproduce in our dev environment