How to find list of Accounts a User has access to ?
I have a requirment to create a service which takes input as a user ( userid) and the service needs to return the list of Accounts the user has access to. The user can get access to account to all possible ways that salesforce can provide (Sharing rules, Role Hierharchies, Record Ownership, Account Team etc...).
I looked around on AccountShare object, GroupMember, UserRecordAcess, Role object. but could not really connect all the dots together to come up with logic to accomplish this.
USerRecordAccess has the details but you have to provide the USerid and Recordid in order to pull the records which does not fit my requirment.
Looking for any guidance.
Functionally speaking "public with sharing" should do the trick,
The with sharing keyword allows you to specify that the sharing rules for the current user be taken into account for a class. You have to explicitly set this keyword for the class because Apex code runs in system context. In system context, Apex code has access to all objects and fields— object permissions, field-level security, sharing rules aren’t applied for the current user.
One more good read : https://developer.salesforce.com/page/Enforcing_CRUD_and_FLS