SELECT Id, ParentId FROM sObject__Share where UserOrGroupId = :UserId
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.Sign up to join this community
Following query works for me fetching from
<your_customobject>__share and RowCause will give you the reason of sharing
The reason why the user or group is being granted access. The reason determines the type of sharing, which controls who can alter the sharing record. This field cannot be updated.
SELECT Id, UserOrGroupId, RowCause FROM Test__share WHERE ParentId = 'a1Cq0000003d58H'
For standard object like Case, you need to fetch from
SELECT Id, UserOrGroupId, RowCause FROM Caseshare WHERE CaseId = '500q0000003Q38g'
This actually works. My problem was with a null pointer because of a related record that was not available when I load the page. This even worked for when there was manual sharing.
I don't think you can query "
sObject__Share" like that. You will have to query each object individually.
Try using something like Schema.getGlobalDescribe(); to get the list of all sObjects. You can then parse through the result, going object by object and running your Query for each one. (For orgs will lots of objects, be wary of hitting any query limits)