Backendless Support
 

Loading the first object from a data table using API

Backendless Service Platform offers a developer an API for loading the very first object created in the table. 

The first object is determined by the value in the created column - Backendless picks the one with the smallest timestamp.

The code below demonstrates loading an object from the Person table:

The Person class used in the code below is:

import java.util.Date;
public class Person
{
 public int age;
 public String name;
 public Date birthdate;
}
Asynchronous sample API (Android and Plain Java):
Backendless.Data.of( Person.class ).findFirst( new AsyncCallback<Person>()
{
 @Override
 public void handleResponse( Person firstPerson )
 {
 System.out.println( "Name - " + firstPerson.name );
 System.out.println( "Age - " + firstPerson.age );
 System.out.println( "Birthdate - " + firstPerson.birthdate );
 }
 @Override
 public void handleFault( BackendlessFault backendlessFault )
 {
 System.out.println( "Server reported an error - " + backendlessFault.getMessage() );
 }
} );
Synchronous sample API (Plain Java only):
Person firstPerson = Backendless.Data.of( Person.class ).findFirst();
System.out.println( "Name - " + firstPerson.name );
System.out.println( "Age - " + firstPerson.age );
System.out.println( "Birthdate - " + firstPerson.birthdate );
The code produces the following output:
Name - Spiderman
Age - 30
Birthdate - Tue Apr 09 18:00:00 CST 1985
Is article helpful?