function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Li LeeLi Lee 

How to use SOQL query my own records and records shared to me at once?

Hi all,

I want to use one SOQL to query my own records and all records shared to me. But I don't know how to write this SOQL, do you have any idea how to write this SOQL? 

Thanks for you help.

Best wishes,
Lee
Best Answer chosen by Li Lee
AnudeepAnudeep (Salesforce Developers) 
Leo - To get all records shared to a user
 
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'

See the following post to learn more