I had this use case where i need to run the entire class in 'respecting sharing rules of org'
But in there i had to query Entitysubscirption object
list<EntitySubscription>listt = [Select c.SubscriberId ,c.parentid From EntitySubscription c where c.parentid in :Allremaningids and c.subscriberId = :UserInfo.getUserId() ];
This will give me below error when run as a non-admin user.
Implementation restriction: EntitySubscription only allows security evaluation for non-admin users when LIMIT is specified and at most 1000
Now how i dealt with this,
- I marked the whole class as without sharing. This works because as its obvious,it runs as system admin.But disadvantage was i had to write explicit queries to enforce sharing and maintenance in future is going to be difficult ,if sharing changes.
- I marked all the class as with sharing. I declared an inner class without sharing,executed the query there . Then i create object in outerclass,call list listt = obj.method(Id id); This works as i think innerclass is being run in without sharing and other class respects sharing.
Now i dont really know whether there is any other disadvantage for this approach?like limits etc?Anyone any idea?