Backendless Support
 

Fetching application's user objects

User accounts of a Backendless app are managed by the User Service. However, the data for the accounts is stored in the Data Service storage. As a result, it is possible to use the Data Service API to load the user objects for an application. Moreover, any search queries, paging and sorting supported by the Data Service API apply directly to fetching user accounts.

Consider an application with the following user accounts: 

The sample below demonstrates loading all user objects in an app. It would be a matter of modifying the search query parameters to enabling sorting or additional data filtering (i.e. loading with an SQL query, aka the "where clause").

                                            For Objective - C and Swift implementations CLICK HERE

Asynchronous sample (Android and Plain Java):

Backendless.Data.of( BackendlessUser.class ).find( new AsyncCallback<BackendlessCollection<BackendlessUser>>()
{
 @Override
 public void handleResponse( BackendlessCollection<BackendlessUser> users )
 {
 Iterator<BackendlessUser> userIterator = users.getCurrentPage().iterator();
 while( userIterator.hasNext() )
 {
 BackendlessUser user = userIterator.next();
 System.out.println( "Email - " + user.getEmail() );
 System.out.println( "User ID - " + user.getUserId() );
 System.out.println( "Phone Number - " + user.getProperty( "phoneNumber" ) );
 System.out.println( "============================" );
 }
 }
 @Override
 public void handleFault( BackendlessFault backendlessFault )
 {
 System.out.println( "Server reported an error - " + backendlessFault.getMessage() );
 }
} );
Synchronous sample (Plain Java only):
BackendlessCollection<BackendlessUser> users = Backendless.Data.of( BackendlessUser.class ).find();
Iterator<BackendlessUser> userIterator = users.getCurrentPage().iterator();
while( userIterator.hasNext() )
{
 BackendlessUser user = userIterator.next();
 System.out.println( "Email - " + user.getEmail() );
 System.out.println( "User ID - " + user.getUserId() );
 System.out.println( "Phone Number - " + user.getProperty( "phoneNumber" ) );
 System.out.println( "============================" );
}
The program output is:
Email - foo@backendless.com
User ID - DC7A6B12-7249-3E8E-FF66-0E8A26743A00
Phone Number - 314-987-6543
============================
Email - spidey@backendless.com
User ID - D866FD8A-54BC-99CF-FF16-05265D15A100
Phone Number - 512-123-4567
============================
Email - goblin@backendless.com
User ID - 52040411-97A5-5E34-FF00-83FCAD51E500
Phone Number - 212-555-1212
============================

NOTICE: the code uses the find() method from the Data Service API. 

IMPORTANT: the demonstrated approach and all its variations are applicable to the Users table in Backendless.

Is article helpful?