SELECT Id, ParentId FROM sObject__Share where UserOrGroupId = :UserId
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'
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)