View the last contact date for BlackBerry devices

You can view the last contact date for multiple BlackBerry® devices by searching for the user accounts and accessing the lastContactDate attribute in the EmailCommonUserSearchResultServiceAttributesType class in the search result. If you already have a search result for the user accounts you want to find, you can reuse the search result and begin looping through the results to find the last contact date.
Before you begin: Retrieve the userDisplayName string array for the user accounts assigned to the BlackBerry devices you want to find.
  1. Specify the search criteria.
    UserSearchCriteria searchCriteria = new UserSearchCriteria();
    BASUserSearchCriteriaServiceAttributes basServiceAttributes = new BASUserSearchCriteriaServiceAttributes();
    basServiceAttributes.displayName = userDisplayName;
    searchCriteria.userSearchCriteriaServiceAttributes = new UserSearchCriteriaServiceAttributesType[1];
    searchCriteria.userSearchCriteriaServiceAttributes[0] = basServiceAttributes;
  2. Specify the order that you want the results returned in. The following code sample returns the results alphabetically by display name. To order the results by the last contact date, use the LAST_CONTACT_DATE enumeration type in the EmailCommonSearchResultSortByEnum class.
    BASUserSearchResultSortByEnum sortBy = new BASUserSearchResultSortByEnum();
    sortBy.@enum = BASUserSearchResultSortByEnumType.DISPLAY_NAME;
    sortBy.enumSpecified = true;
    findUsersRequest.sortBy = sortBy;
    findUsersRequest.sortAscendingOrder = true;
  3. Specify the maximum number of results returned for each page, specify the locale that you are using, and specify the lastResultElement as null.
    FindUsers findUsersRequest = new findUsers();
    findUsersRequest.locale.pageSize = 3;
    findUsersRequest.lastResultElement = null; 
    findUsersRequest.locale = locale;
    findUsersRequest.searchCriteria = searchCriteria;
  4. Invoke findUsers(). Check the result for errors and handle any errors.
    findUsersResponse response = coreWebService.findUsers(findUsersRequest);
    findUsersResult result = response.returnValue;
    if (result.findUsersReturnStatus.code != FindUsersReturnStatusEnumType.SUCCESS)
        // handle any errors
  5. Loop through the result to get the ID of each user account that matches the search criteria.
    while ((result.findUsersReturnStatus.code == FindUsersReturnStatusEnumType.SUCCESS) && (result.userSearchResult != null))
        for (int i = 0; i < response.returnValue.userSearchResult.Length; i++)
           UserSearchResult searchResult = response.returnValue.userSearchResult[i];
           UserSearchResultServiceAttributesType[] serviceAttributes = searchResult.userSearchResultServiceAttributes;
           for (int j = 0; j < serviceAttributes.Length; j++)
  6. For each user account, store or print the last contact date, the user ID, and any other attributes you want, such as the display name.
                if (serviceAttributes[j].GetType().Equals(typeof(BASUserSearchResultServiceAttributes)))
                    BASUserSearchResultServiceAttributesType BASAttributes = serviceAttributes[j] as BASUserSearchResultServiceAttributesType;
                    String currentUserID = BASAttributes.userId;
                    String currentDisplayName = BASAttributes.displayName;
                    //Do something with the user name and display name here. For example, print to the UI
                if (serviceAttributes[j].GetType().Equals(typeof(EmailCommonUserSearchResultServiceAttributes)))
                    EmailCommonUserSearchResultServiceAttributesType emailAttributes = serviceAttributes[j] as EmailCommonUserSearchResultServiceAttributesType;
                    String lastContact = emailAttributes.lastContactDate;
                    // Do something with the last contact date here.  
  7. To retrieve the next page of results, specify the last result element from the previous findUsers() request and invoke the findUsers() method again.
        lastResultElement = result.userSearchResult[response.returnValue.userSearchResult.Length - 1];
        findUsersRequest.lastResultElement = lastResultElement;
        response = coreWebService.findUsers(findUsersRequest);
        result = response.returnValue;
  8. Check the result for errors and handle any errors.
    if(result.findUsersReturnStatus.code != FindUsersReturnStatusEnumType.SUCCESS)
        // handle any errors

Was this information helpful? Send us your comments.