Is it possible to use a subquery to obtain a list of that object's __Share's?

For example: ObjA has been manually shared via apex. At some point I may want to query information about ObjA and get a list of its shares. I'd like to be able to do something like this:

   (Select Id, UserOrGroupdID FROM ObjA__Shares) 
    ObjA__c Where Id = :someId];

From my testing in the dev console, it doesn't not appear to be the case. For the record I've tried ObjA__Share and ObjA__Shares to no avail.



This is perfectly possible. You are just using the wrong syntax.

This will work:

SELECT ID, Name, (SELECT ID, UserOrGroupdID FROM Shares) FROM ObjA__c WHERE ID = :someId;

In order to find the right child relationship names, I always use the Schema Explorer in Eclipse. By browsing to an object and then selecting 'Child Relationships' you can find out the 'Relationship Name' of the child relationship.

  • 1
    Thanks! That'll do nicely. I'm not an Eclipse user but that's darn good to know. I'd vote you up but I don't quite have enough rep yet! – lifewithryan Oct 2 '14 at 20:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.