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 CaseShare object
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.
answered May 15, 2017 at 16:28 Andrew Mayes Andrew Mayes 97 3 3 silver badges 8 8 bronze badgesWelcome to SFSE! Please take a moment to visit the help center, scroll through the tour, and read How to Ask. Remember to include the actual problem you have in the question, specifically the null pointer part. The query you've written is actually correct so in which case no one would be able to help you because there's nothing to help with!
Commented May 15, 2017 at 16:38Thanks Dan, I realized this after the fact. I was trying to be specific on the question but I will take a look.
Commented May 15, 2017 at 17:29I 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)
answered May 15, 2017 at 16:30 sunnymatharuuk sunnymatharuuk 153 5 5 bronze badgesI think he's using sObject__Share as a general term to avoid using the API name of a real object that would typically make less sense to us outside his Org. Querying based on something like Schema.getGlobalDescribe() would rapidly smash limits and simply wouldn't be sustainable as an org grows, as you correctly identify through query limits. Additionally, I'd expect you to rapidly hit collection size limits too.
Commented May 15, 2017 at 16:35Agreed Dan, hence my bit about limits in brackets. I don't think it's sustainable for a large enterprise org, but is plenty fine for small orgs that would never be close to these limits. Also, getGlobalDescribe would surely constitue only one call. Thereafter, there will be as many calls as there are sobjects. If doing this inside apex, I can't think of a simple way to otherwise do this. @AndrewMayes , if this works as you say, can you please mark as such. Alternatively, I would be interested if anyone had any less potentially-limit-killing mechanisms
Commented May 15, 2017 at 16:54You're right. If you absolutely had to, you'd need to put restrictions in place akin to Valdiation Rules (e.g. "You may only select up to 5 objects", "Showing 1000 records of x", that type of thing).