2

I trying build query: Start from AuthSession and go to User and then go to PermissionSet.

Maybe someone help me with query (SELECT Id FROM User.PermissionSetAssignment WHERE AssigneeId=:UserId AND PermissionSetId = 'xxxxxxx')

SELECT UserId, 
    (SELECT Id 
        FROM 
        User.PermissionSetAssignment 
        WHERE 
        AssigneeId=:UserId AND 
        PermissionSetId = 'xxxxxxx') 
    FROM 
    AuthSession 
    WHERE 
    UserType = 'Customer Portal User'

Please lem me know if I wrong thinking.

1
  • Why would you add the [appcloud] tag to this question? It may deserve some tags in addition to [soql], but that one does not seem to have anything to do with what is being asked here.
    – Adrian Larson
    Commented Mar 27, 2018 at 5:00

2 Answers 2

1
  • You can't do a SOQL query on an object called "User.PermissionSetAssignment" because that doesn't exist.
  • There is no relationship between PermissionSetAssignment and AuthSession.
  • The field on AuthSession is UsersId, not UserId.

You will need to make separate queries and the join them using a map or a similar technique.

Set<Id> myUsers = new Set<ID>();
for(AuthSession a : [SELECT UsersId FROM AuthSession WHERE UserType = 'Customer Portal User']){
    myUsers.add(a.UsersId);
}

List<PermissionSetAssignment> PSAs = [SELECT Id FROM PermissionSetAssignment WHERE AssigneeId IN :myUsers AND PermissionSetId = 'xxxxxxx'];

That should work.

0
2

This query is one way to do it (assuming you don't have a User Id upfront that you want to filter by but instead want all the matching Users); replace the ? with the PermissionSet field names you want to access:

for (PermissionSetAssignment psa : [
        select Id, PermissionSet.?, PermissionSet.?, PermissionSet.?
        from PermissionSetAssignment
        where AssigneeId in (
                select UsersId
                from AuthSession
                where UserType = 'Customer Portal User'
                )
        and PermissionSetId = 'xxxxxxx'
        ]) {
    PermissionSet ps = psa.PermissionSet;
    ...
}

This User, Sharing, and Permission Objects ERD is helpful as is this AuthSession documentation that includes the atypical field name of UsersId.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .