So I have custom REST API with Get method where request parameter is PublicGroup Name and Response is list of Users from that publicGroup.

Global with sharing class UsersService {

    Global static List<User> UsersService() {

        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String publicGroupName = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        String formatString = publicGroupName.replaceAll('[+]',' ');
        List<Group> groupId = [SELECT Id, Name FROM Group WHERE Name =:formatString LIMIT 1];
        List<User> publicGroupUsers = new List<User>();

        for(User usr : [SELECT Id, FirstName, LastName, Email FROM User WHERE ID IN (SELECT UserORGroupID FROM GroupMember WHERE GroupID IN :groupID) AND IsActive=true]){
        return publicGroupUsers;

It's limited to 1 public group name as you can see. How do I get it to work for List of publicgroup names in request?

eg. /services/apexrest/GetUsers/group1;group2;test+group3

and response will be list of Users from all 3 publicgroup.

1 Answer 1


Some String manipulation should work for you.

  1. Break the publicGroupName into parts by a known delimiter (';' in your example).
  2. Format each groupName using your replaceAll call
  3. Query Group filtered by a list of Names (may need to remove your LIMIT)


List<String> groupNames = req.requestURI.substring(req.requestURI.lastIndexOf('/') + 1).split(';');

for (String groupName : groupNames) {
    groupName.replaceAll('[+]',' ');

List<Group> groupId = [SELECT Id, Name FROM Group WHERE Name in :groupNames LIMIT 1];

You must log in to answer this question.

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