0

Does anyone know if it is possible to programmatically clear all of the data in a Backendless table at once? I found this article that shows how to remove individual objects one at a time but nothing on clearing the whole table at once: https://backendless.com/documentation/data/android/data_deleting_data_objects.htm

I figured out a way to do it but I don't know how efficient it is. Basically, I have a Class called LocalPhoneNum, which make up the objects that will be saved in my app table. The class contains a userID, name and phone num. I query the table to find a user with a specific email (right now there's just one user), then use the foundContacts variable in a loop to delete each object one by one.

String whereClause = "userEmailID = mark";
    BackendlessDataQuery dataQuery = new BackendlessDataQuery();
    dataQuery.setWhereClause( whereClause );

    Backendless.Persistence.of(LocalPhoneNum.class).find(dataQuery, new AsyncCallback<BackendlessCollection<LocalPhoneNum>>(){
        @Override
        public void handleResponse( BackendlessCollection<LocalPhoneNum> foundContacts )
        {
            for (LocalPhoneNum temp : foundContacts.getData()){
                Backendless.Persistence.of( LocalPhoneNum.class ).remove( temp, new AsyncCallback<Long>()
                {
                    public void handleResponse( Long response )
                    {
                        Toast.makeText(getActivity(), "DELETED", Toast.LENGTH_LONG).show();
                    }
                    public void handleFault( BackendlessFault fault )
                    {
                        Toast.makeText(getActivity(), "NOT DELETED "+fault, Toast.LENGTH_LONG).show();
                    }
                } );
            }

Please let me know if there is a better solution or if this one is fine. Thank you!

Mark F
  • 1,523
  • 3
  • 23
  • 41

1 Answers1

0

Use the "bulk delete" operation with the 'where' query like "objectId is not null": https://backendless.com/documentation/data/rest/data_deleting_data_objects.htm

Mark Piller
  • 1,046
  • 1
  • 7
  • 6
  • I can't seem to find a quick solution for Android. I added some code to my question above that seems to solve the problem. Please let me know if this is efficient or if there is another solution. Thank you! – Mark F Jul 26 '16 at 20:05
  • (Efficiently) deleting multiple records with a single query is possible only with the REST API. That API is called "bulk delete", see the page I linked to in my response and search for "bulk delete" in there. The code you posted would work, but it is very inefficient since it makes a request for every object. With the bulk delete, there is only one request that gets the job done. – Mark Piller Jul 27 '16 at 01:51
  • Are there an examples of using this in Android Studio? I'm just not sure how it would be implemented within the app? – Mark F Jul 27 '16 at 12:38
  • Here's a discussion on how to make a REST call in Java: http://stackoverflow.com/questions/3913502/restful-call-in-java – Mark Piller Jul 27 '16 at 14:08
  • So I'm closer but am lost with the syntax, especially with the implementation of Request Headers. I put up the following post. Any help would be appreciated. Thank you http://stackoverflow.com/questions/38620536/backendless-bulk-delete-syntax – Mark F Jul 27 '16 at 18:26