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 userSearchCriteria=new UserSearchCriteria(); 
    BASUserSearchCriteriaServiceAttributes BASCriteria=new BASUserSearchCriteriaServiceAttributes();
  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 sortByEnum=new BASUserSearchResultSortByEnum();
    boolean sortAscending=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.
    int pageSize = 5;
    String locale = locale;
    UserSearchResult lastResultElement = null;
  4. Invoke findUsers(). Check the result for errors and handle any errors.
    FindUsersResult result=coreWebService.findUsers(userSearchCriteria, sortByEnum, sortAscending, locale, lastResultElement, pageSize);
    if (result.getFindUsersReturnStatus().getCode() != 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.getFindUsersReturnStatus().getCode() == FindUsersReturnStatusEnumType.SUCCESS) && (result.getUserSearchResult()!= null)) 
        List<UserSearchResult> results=result.getUserSearchResult();
        for (UserSearchResult itr:results) 
            for (UserSearchResultServiceAttributesType itr2: itr.getUserSearchResultServiceAttributes()) 
  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 (itr2 instanceof BASUserSearchResultServiceAttributesType) 
                    BASUserSearchResultServiceAttributesType BASAttributes=(BASUserSearchResultServiceAttributesType) itr2;                
                    String currentUserID = BASAttributes.getUserId(); 
                    String currentDisplayName = BASAttributes.getDisplayName();
                    // Do something with the user name and display name here. For example, print to the UI 
                if (itr2 instanceof EmailCommonUserSearchResultServiceAttributesType) 
                    EmailCommonUserSearchResultServiceAttributesType emailAttributes=(EmailCommonUserSearchResultServiceAttributesType) itr2;
                    String lastContact = emailAttributes.getLastContactDate(); 
                    // Do something with 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.
        result=coreWebService.findUsers(userSearchCriteria, sortByEnum, sortAscending, locale, result.getUserSearchResult().get(result.getUserSearchResult().size()-1), pageSize); 
  8. Check the result for errors and handle any errors.
    if(result.getFindUsersReturnStatus().getCode() != FindUsersReturnStatusEnumType.SUCCESS)
        // handle any errors

Was this information helpful? Send us your comments.