According to the Salesforce manual describing the access control using the object "UserRecordAccess" [here], I'd like to obtain a list of permissions for a given "User" and "Case" in Salesforce.
Using the interactive workbench tool, I received the following syntax error at the construction of this query:
SOQL Query:
SELECT RecordId, HasReadAccess FROM UserRecordAccess WHERE UserId = 'abc123xyz..' AND RecordId in (SELECT Id FROM Case WHERE CaseNumber = '10001026')
Validation Message at Workbench:
MALFORMED_QUERY: The left operand field in the where expression for outer query should be an id field, cannot use: 'RecordId'
Is an alternate syntax available in SOQL to build such type of nested query?
Solution found: As a solution path, following the answer posted below, I've wrote a code in an APEX script with a REST interface, which executes the three SOQL queries in sequence. See the code:
@RestResource(urlMapping='/sfcheckap/*')
// sample: /services/apexrest/sfcheckap/00001028&[email protected]
//
global with sharing class MyRestResource1 {
@HttpGet
global static Boolean doGet() {
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
String myinput = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
List<String> inputList = myinput.split('&');
String mycase = inputList[0];
String myemail = inputList[1];
sObject s1 = [SELECT Id FROM User WHERE Email = :myemail];
ID MyUserId = s1.ID;
Case s2 = [SELECT Id FROM Case WHERE CaseNumber = :mycase LIMIT 1];
ID MyCaseId = s2.ID;
System.debug('Dynamic MyCaseId is: ' + MyCaseId);
UserRecordAccess s3 = [SELECT RecordId, HasReadAccess FROM UserRecordAccess
WHERE UserId = :MyUserId AND RecordId = :MyCaseId];
ID MyRecordId = s3.ID;
Boolean result = s3.HasReadAccess;
return result;
}
}