0

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;        
    }  
}

1 Answer 1

1

You're SOQL Query in the WHERE clause will return a set of id's (SET<ID>) then the field being compared to one instance of the set should of the same datatype I believe.

Here is what the UserAccessRecord sObject looks like:

global class UserRecordAccess extends SObject 
{
    global Boolean HasAllAccess;
    global Boolean HasDeleteAccess;
    global Boolean HasEditAccess;
    global Boolean HasReadAccess;
    global Boolean HasTransferAccess;
    global String MaxAccessLevel;
    global String RecordId;
    global SObjectType SObjectType;
    global User User;
    global Id UserId;
    global APTTaskTemplate__c UserRecordAccess;

    global UserRecordAccess()
    {
    }
}

As you can see UserAccessRecord.RecordId is of type String.

You should be able to do this in 2 SOQL queries I believe, first SOQL Query would get the Case Ids and convert it to a List Type. Second would use that list.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.