You need to sign in to do that
Don't have an account?

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.
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.
public List<Account> accList{get;set;}
public accountList(){
accList = new List<Account>();
for(Account a : [SELECT Name FROM Account]){
accList.add(a);
system.debug('***a***'+accList);
}
}
}
Here is a link of a blog which help you to find the record is accessable or not for a user.
http://www.codespokes.com/2014/06/salesforce-record-accessibility.html
IF it helps you than please mark it as a solution and ENJOY APEX (http://www.codespokes.com/2014/06/salesforce-record-accessibility.html)
I am ignoring OWD. Permission Sets, profiles as we won't be providing access to accounts through that. Our access to account will be mimited to Sharing and Role Hierarchy access. I stumbled on the some notes where users are using combination of Accountshare, Group, Group member and userrole tables to derive this. I am trying to understand the data model for this to determine the logic/joins.
List<AccountShare> shareList = [SELECT AccountId, UserOrGroupId FROM AccountShare WHERE UserOrGroupId =: useridList ];
for(AccountShare s : shareList){
accountIds.add(AccountId);
}
List<Account> acc = [SELECT Name FROM Account WHERE Id IN : accountIds];
Hope this works.
If the access is provided directly to user or the group he is in, the accountshare object will store the direct entry which you can retrieve. The complexity is in the case where the access is not provided directly but the user inherits through Role Hierarchy or groups within groups. Some kind of recursuve logic will need to be written for this. BAsed on some notes in the net looks like salesforce automatically explodes the role hierarchy and creates this internal groups which you can use. I could not get that part, the documentation of the Group and Group member table gives some explanation but it not very clear. I opened a SR with Salesforce to get their opinion. Lets see. So far it does not look encouraging.
Would it be useful for your purposes to be able to test a user's access against a known set of Accounts? If so, you can use the UserRecordAccess function documented here: http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_userrecordaccess.htm
That feature allows you to manage a long-running callout that is synchronous to the user, but processes on our message queues and so not constrained by our long-running callout limit.
Secondly, the recursive derivation of the Record Access through Group(Member) tables - Is the performance only the issue OR is there any other technical limitation for this (apart from the complexity) ? I was going to limit the Role/Hierarchy Tree traversing up to fixed level - based on our needs here the tree should not be more then 4 level deep. Can you point to any other documentation which clearly defines the data model AND how the records are stored for the Hierarchies through Role and nested Groups.? Want to study this approch before I discard. Also, some one mentioned we can run apex code under a specifc user context but that feature is only available in Sandbox not Production. Is this correct ?
I have a similar situatuin where i need to query all records of Opportunity accessible to a user.
How did u solve the issue. Let me know if u see this msg asa.
Thanks in advance.
Laxman
Could you solve the problem by using AccountShare+GroupMember?
Thanks.
I also have same requirement. I trying with the AccountShare object. As there are nested groups and groups for Roles, RoleAndSubordinates,RoleAndSubordinatesInternal, territory and TerritoryAndSubordinates I am not sure how to fecth user from these groups. looking for some guidance on this.
Thanks.