[SalesForce] Get List of Permission set assigned to the user

I want to get the list of permission set assigned to loggedin user.
And a conditional check one that.

If a user has 'TestABC' permission set assigned then boolean value should be true

I am using this approach

List<PermissionSetAssignment> lstcurrentUserPerSet =    [   SELECT Id, PermissionSet.Name,AssigneeId
                                                                FROM PermissionSetAssignment
                                                                WHERE AssigneeId = :Userinfo.getUserId() ];
system.debug('##lstcurrentUserPerSet' + lstcurrentUserPerSet);

for (PermissionSetAssignment psa: lstcurrentUserPerSet)
{
    system.debug('##psa.PermissionSet.Name' + psa.PermissionSet.Name);
    if(psa.PermissionSet.Name.equals('TestABC'))
                Test = true;
    else
            Test = false;
}

I am not able to get any values in debug log. The list is not retreving any value it seems

Best Answer

Is there a requirement that you need all the Permission sets to be queried for some other use? Or else if its just to check why don't we directly use this query

SELECT count(Id) FROM PermissionSetAssignment WHERE AssigneeId = :Userinfo.getUserId() AND PermissionSet.Name = '-permission set api name here-'

If result = 1 means the permission set is assigned for current user else if result = 0 means its not.