2

I have admin API access for my organization. I'd like to run the same SOQL query, but get back results as visible to various users in my org: running "SELECT Name FROM Account" for user A, should only return account names accessible to user A.

I know this is easy if each user provides my application with their password and security token, so I can log in as them and run the query, but I want to do this only using my admin account.

this is very similar to:

Salesforce: impersonation using the API

but in this case I do have access to the data, I just want to filter it as though the request came from a specific user. It looks like there's an Apex "unit testing" method called System.RunAs() which looks close, but I want to run this via REST.

4

1 回答 1

1

我认为您可以使用HasReadAccessfrom UserRecordAccesstable 过滤第一个 SOQL 查询。

您可以尝试先构建一组,RecordIDs然后使用它来过滤帐户查询。

Set<ID> sRecordIDs = [SELECT RecordID FROM UserRecordAccess WHERE UserId = :u AND HasReadAccess = True];
Account[] accs =[SELECT ID,Name FROM Account WHERE Id in :sRecordIDs];

有关官方文档的更多详细信息

于 2012-09-11T13:27:04.910 回答