Search for a user account on the messaging server

You can use any attribute in the MailStoreUserSearchCriteriaType class to search for user accounts on the messaging server . The findMailStoreUsers() method can return multiple results if the search criteria is not unique. The findMailStoreUsers() method adds wildcard characters to the beginning and end of all search terms. For example, if you search using an email address for the string james.lambier, the result could contain the user accounts for,, and The following code sample searches for a user account using a complete, unique email address in the search criteria.
Before you begin: Retrieve the emailAddress string for the user you want to find.
  1. Create the search criteria. To search using more than one of the criteria in the MailStoreUserSearchCriteriaType class, specify the additional criteria after the email address.
    MailStoreUserSearchCriteria criteria = new MailStoreUserSearchCriteria();
    criteria.emailAddress = emailAddress;
  2. Specify the order that the BlackBerry® Administration API returns the results in. The following code sample assumes that the search criteria is unique and only one result is returned, but you should always specify the order.
    MailStoreUserSearchResultSortByEnum sortByEnum = new MailStoreUserSearchResultSortByEnum();
    sortByEnum.@enum = MailStoreUserSearchResultSortByEnumType.DISPLAY_NAME;
    sortByEnum.enumSpecified = true;
  3. Specify the page size and the locale.
    int pageSize = 1;
    String locale = "en_US";
  4. Invoke findMailStoreUsers(). You use the pageCriteria parameter when multiple pages of results are returned. To change the number of results per page, use the pageSize parameter. If there are multiple pages of results, set the pageCriteria parameter to null to obtain the first page of the results. To retrieve the next page of results, invoke the findMailStoreUsers() method again and specify the last value in the results from the previous search as the pageCriteria parameter.
    findMailStoreUsers findMailStoreUsersRequest = new findMailStoreUsers();
    findMailStoreUsersRequest.searchCriteria = criteria;
    findMailStoreUsersRequest.sortByCriteria = sortByEnum;
    findMailStoreUsersRequest.sortByAscendingOrder = true;
    findMailStoreUsersRequest.criteriaAndResultSetLocale = locale;
    findMailStoreUsersRequest.pageCriteria = null;
    findMailStoreUsersRequest.pageSize = pageSize;
    FindMailStoreUsersResponse findMailStoreUsersResponse = emailExchangeWebService.findMailStoreUsers(findMailStoreUsersRequest);
    FindMailStoreUsersResult result = findMailStoreUsersResponse.returnValue;
  5. Check the result for errors and handle any errors.
    if ((result.findMailStoreUsersReturnStatus.code == FindMailStoreUsersReturnStatusEnumType.SUCCESS) && (result.mailStoreUserSearchResult.Length == 1))
        return result.mailStoreUserSearchResult[0];
        // handle any errors    
Previous topic: Managing user accounts

Was this information helpful? Send us your comments.