Skip to main content

Is it possible to make a soql query that will return records owned by the user running it or owned by a queue that the user is a member of?

 

ideally, this would work but it sounds like that scope only works for ProcessInstanceWorkitem object

Select id from case USING SCOPE mine_and_my_groups

7 respostas
  1. Ruchit Patel (Cognizant) Forum Ambassador
    2 de dez. de 2022, 17:48

    Hi @Andrew Russo you can try the following code script in Execute Anonymous window.

    List<case> caseList = new List<case>();

    String userid = UserInfo.getUserId();

    set<string> queueIds = new set<string>();

    for(GroupMember gm : [SELECT Id, UserOrGroupId, GroupId FROM GroupMember WHERE UserOrGroupId = :userid AND GroupId IN ( SELECT Id FROM Group WHERE Type = 'Queue' )]) {

    queueIds.add(gm.GroupId);

    }

    string qry = 'SELECT ID FROM Case WHERE OwnerId =:userid';

    if(!queueIds.isEmpty()) {

    qry += ' OR OwnerId IN : queueIds';

    }

    for(case c : database.query(qry)) {

    caseList.add(c);

    }

    system.debug('---caseList--->>'+caseList);

0/9000