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
birthusbirthus 

UserRecordAccess query problem.

Hi all,

I have to check if some users has access to some accounts.
I tryed query UserRecordAccess but as I know I cant put two list in conditions...
I tryed something like that:

[    SELECT     RecordId
     FROM     UserRecordAccess
      WHERE     HasEditAccess = true ANDRecordId IN : sRecrdsIds  AND UserId IN : sUsersIds
  ];

Is it even possible to check if for eg 10 users has access to 10 accounts?
Or mayby is there some other, smarter way to achive that? :)

HsethHseth

The UserRecordAccess does not allow you to have filtering on list of userids. What you could do instead is to select all the users who have the edit acess on the selected records and put them in a map<userid, record> and then check the access for your users using the userid as a key in the map.

birthusbirthus
Thanks for your answer, but I am aware of that.
As I said I try to put two list (but this is Impossible), so I am looking for solution which will give me simular result like my query.
And I wonder if it is even possible....

Map <userid, record > will be nice if I will check access.
But creating this map mean put query in the loop, isn't it?
For 10 users I will have to put 10 querys?

Is it possible to achieve my goal in any other way not using query in the loop?
HsethHseth

Yes I think there is no way currently to avoid the queries. The map would help you keep the data across various loops.