Backendless Support
 

Deleting persistent objects using Data Service API

Deleting an object in Backendless using the API is just as easy as creating or updating a one. 

In case an object has relations, while deleting an object its relations are broken up and the related objects are not deleted from the system.

The sample below retrieves the first object from a table and deletes it:

Person class - corresponds to the Person table show below:
package com.mbaas.sample;
import java.util.Date;
public class Person
{
 public int age;
 public String name;
 public Date birthdate;
 public String objectId;
}
Asynchronous API sample (Android and Plain Java):
final AsyncCallback<Long> deleteResponder = new AsyncCallback<Long>()
{
 @Override
 public void handleResponse( Long timestamp )
 {
 System.out.println( "Object removed at " + new Date( timestamp ).toString() );
 }
 @Override
 public void handleFault( BackendlessFault backendlessFault )
 {
 }
};
Backendless.Data.of( Person.class ).findLast( new AsyncCallback<Person>()
{
 @Override
 public void handleResponse( Person person )
 {
 System.out.println( "Loaded object. Name - " + person.name );
 Backendless.Data.of( Person.class ).remove( person, deleteResponder );
 }
 @Override
 public void handleFault( BackendlessFault backendlessFault )
 {
 System.out.println( "Server reported an error - " + backendlessFault.getMessage() );
 }
} );
Synchronous API sample (Plain Java only):
Person person = Backendless.Data.of( Person.class ).findLast();
System.out.println( "Loaded object. Name - " + person.name );
long timestamp = Backendless.Data.of( Person.class ).remove( person );
System.out.println( "Object removed at " + new Date( timestamp ).toString() );

Once an object is deleted, it is completely removed from the system.

Is article helpful?